var students=[{
no:1001,
name:'张三'
},
{
no:1002,
name:'李四'
},
{
no:1003,
name:'王五'
},{
no:1004,
name:'赵六'
}]
// 删除学号为1001,1002的学生
for(let i = students.length - 1; i >= 0; i--){
if(students[i].no==1001 || students[i].no==1002){
students.splice(i,1)
}
}
console.log(students)
输出(2) [{…}, {…}]
0:
name: “王五”
no: 1003
proto: Object
1:
name: “赵六”
no: 1004
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// 删除索引号1,4,8的元素
arr.splice(7,1)
arr.splice(3,1)
arr.splice(0,1)
console.log(arr)
输出(7) [2, 3, 5, 6, 7, 9, 10]
这篇博客探讨了如何在JavaScript中从后往前删除数组中的多个元素。通过实例展示了如何操作数组,输出展示了删除过程,包括两个对象元素和一个数字序列。
152

被折叠的 条评论
为什么被折叠?



