I have encountered this problem, My aim is to filter objectOfProductsById and remove all id's based on condition, for example, if objectOfProductsById doesn't contain id's from arrOfIds i want to remove data inside objectOfProductsById. How I can achieve this result using ES6 syntax?
let arrOfIds = [2233, 1235, 4455]
let objectOfProductsById = {
2233: {
productName: 'simple product'
},
2211: {
productName: 'simple product2'
},
1111: {
productName: 'simple product2'
},
}
let newObj = Object.entries(objectOfProductsById).forEach(([key, value]) => {
if (!arrOfIds.includes(key)) {
delete objectOfProductsById[key]
}
})
console.log(newObj)