我有一个对象数组,我想根据用户传入的参数来删除特定的项,
removeItem = (title, body){
let myArray = [
{ title : 'title 1', body: 'body of title one' },
{ title : 'title 2', body: 'body of title two' },
{ title : 'title 3', body: 'body of title three' },
]
//the problem is down here
let filteredArray = myArray.filter(item => {
item.title != title || item.body != body
}
// at this point i assume that the filtered array will not
// include the item that i want to remove
// so down here i reset the value of my original array to the filtered one
myArray = filteredArray
但是,以上代码会删除所有内容并返回一个空数组.. 有人能帮忙纠正上述逻辑吗?谢谢。
return item.title != title || item.body != body
。 - DPac