I want to remove the bad
property from every object in the array. Is there a better way to do it than using a for
loop and deleting it from every object?
var array = [{"bad": "something", "good":"something"},{"bad":"something", "good":"something"},...];
for (var i = 0, len = array.length; i < len; i++) {
delete array[i].bad;
}
Just seems like there should be a way to use prototype
, or something. I don’t know. Ideas?
With ES6, you may deconstruct each object to create new one without named attributes:
const newArray = array.map(({dropAttr1, dropAttr2, ...keepAttrs}) => keepAttrs)