// 数组
let arr = [ "", "你", "太", "美" ];
let arrList = arr.filter((x) => x !== "太");
console.log(arrList);
// 数组对象
let arr = [{name:"张三",age:18},{name:"李四",age:19},{name:"王五",age:20}]
let list = arr.filter((val) => val.name !== '张三')
console.log(list);
如果数组中有重复的两个元素,我们只想删除一个元素,我们必须使用另一种方法。
let arr = [ "", "你", "太", "美", "" ];
let arrList = arr.indexOf("");
arr.splice(arrList, 1);
console.log(arr);
// 数组
let arr = [1,2,3,4,5,6]
let list = []
console.log(arr.indexOf(4));
for(let i=0;i<arr.length;i++){
if(i !== arr.indexOf(4)){
list.push(arr[i])
}
}
console.log(list);
// 对象数组
let arr = [{name:"张三",age:18},{name:"李四",age:19},{name:"王五",age:20}]
let list = []
for(let i=0;i<arr.length;i++){
if(arr[i].name !== '张三'){
list.push(arr[i])
}
}
console.log(list);