Answer the question
In order to leave comments, you need to log in
How to iterate over an array of objects to remove one element from the object?
I have an array with objects. I need to loop through an array and in each object add one value and remove one.
Now I'm iterating through the array and adding the value I need, but how can I remove the value I already don't need?
Maybe you can somehow use destructuring, but without this element in the object?
let arr = [
{
name: 'One',
id: 1,
value: 221,
list: [{id: 444}]
},
{
name: 'Two',
id: 2,
value: 233,
list: [{id: 555}]
},
]
arr = arr.map((item)=>{
return {
...item,
isUse: item.list?.length === 0 ? false : true,
};
});
Answer the question
In order to leave comments, you need to log in
I didn’t quite understand what is required
1) Remove an element from an array - filter
2) Remove an element from an object - delete operator
3) Get an object without a specified property - `const {uselessParam, ...newObj} = obj;`
4) Or like this - `Object.fromEntries(Object.entries(obj).filter(...))`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question