How to remove property for all objects in array with JavaScript?

Sometimes, we want to remove property for all objects in array with JavaScript.

In this article, we’ll look at how to remove property for all objects in array with JavaScript.

How to remove property for all objects in array with JavaScript?

To remove property for all objects in array with JavaScript, we can use the rest syntax.

For instance, we write

const newArray = array.map(
  ({ dropAttr1, dropAttr2, ...keepAttrs }) => keepAttrs
);

to call array.map with a callback that get an object with all the properties we want to keep in keepAttrs.

And then we return that as the value.

Conclusion

To remove property for all objects in array with JavaScript, we can use the rest syntax.