I'm trying to remove an item with a property from array object based on the key but it is leaving an empty object. For example,
var items = [{"fruits": ["Apple","Banana"]},{"veggies": ["Potato","Carrot"]}]
So I want to remove the item with the fruits property. This is the code I tried...
var filter = items.map(({ fruits, ...rest }) => rest);
This gave me an output of
[{},{"veggies": ["Potato", "Carrot"]}]
Why is it leaving a trace of an empty object? And how to get rid of that empty object?
itemsan array of objects with a single property, rather than one object with multiple properties?obj.property == "value"orobj.property != "value", just use!obj.propertyor!obj.hasOwnProperty("property")delete items.fruitswould've been enough. Now you need extra, potentially unnecessary steps.