Remove property for all objects in array

javascript, javascript-objects

Solution

The only other ways are cosmetic and are in fact loops.

For example :

array.forEach(function(v){ delete v.bad });

Notes:

- if you want to be compatible with IE8, you'd need a shim for forEach. As you mention prototype, prototype.js also has a shim.

- `delete` is one of the worst "optimization killers". Using it often breaks the performances of your applications. You can't avoid it if you want to really remove a property but you often can either set the property to `undefined` or just build new objects without the property.

Problem

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?

Original source