代码实现如下:
let array = [
{ id: 1, name: '周瑜' },
{ id: 2, name: '王昭君' },
{ id: 3, name: '亚瑟' },
{ id: 4, name: '小乔' },
{ id: 5, name: '大桥' },
{ id: 2, name: '韩信' },
{ id: 5, name: '周瑜' },
];
var arr1 = [];
const arr = array.filter((item) => {
if (item.name == "周瑜") {
arr1.push(item.id)
return arr1
}
});
console.log(arr1.join(','))
console.log(arr1.toLocaleString())
const arr2 = array.filter(item => item.name == "周瑜").map(item => item.id).join(',')
const arrDelete = array.filter((item) => {
return item.id !== 5;
});
console.log(arrDelete)