Ребят, подскажите, пожалуйста. Нужно убрать все объекты с именем chair.
код:
const furniture = [
{ id: 1, type: 'chair', price: 52},
{ id: 2, type: 'chair', price: 76},
{ id: 3, type: 'table', price: 48},
{ id: 4, type: 'table', price: 52},
{ id: 5, type: 'chair', price: 32},
{ id: 6, type: 'cupboard', price: 52},
{ id: 7, type: 'chair', price: 88},
{ id: 8, type: 'cupboard', price: 66},
{ id: 9, type: 'chair', price: 52},
{ id: 10, type: 'cupboard', price: 88},
];
function indexFunc() {
furniture.forEach(function (item) {
if (item.type === 'chair') {
console.log('chair index: ',
item.id)
furniture.splice(
item.id, 1)
}
});
}
indexFunc();
console.log(furniture);
или ссылка:
https://jsfiddle.net/eubznfj0/2/Почему forEach выводит не все объекты, а splice удаляет не то? Что я делаю не так?