0
オブジェクトの配列からアイテムを削除するにはどうすればよいですか? isn isnが配列と一致する項目を削除する必要があるプロパティの配列があります。ここで は一例です:オブジェクトの配列からアイテムを削除するには?
let selectedIsn = [10,15,20,30,40];
let arayObject = [{
isn:10,
name:"Bolt"
}, {
isn:13,
name:"marry"
},{
isn:15,
name:"a"
},{
isn:18,
name:"q"
}, {
isn:20,
name:"marrys"
},{
isn:25,
name:"aa"
},{
isn:30,
name:"qa"
}, {
isn:40,
name:"marrya"
},{
isn:55,
name:"sa"
},{
isn:68,
name:"qas"
}];
let deleteSelected = (q,selectedItems) => {
let arrayNew = q,
count=0;
for (var m = 0; m < q.length; m++) {
let index = selectedItems.indexOf(q[m]["isn"]);
if (index > -1) {
arrayNew.splice(m - count, 1);
count++;
}
}
return arrayNew;
}
deleteSelected(arayObject,selectedIsn);
は、与えられたリストのないすべての要素を削除します。私は何が悪いのか分からない。