Categories
JavaScript Answers

How to delete property from spread operator with JavaScript?

Spread the love

To delete property from spread operator with JavaScript, we use the rest syntax.

For instance, we write

const myObject = {
  a: 1,
  b: 2,
  c: 3,
};
const { b, ...noB } = myObject;
console.log(noB);

to use the rest syntax to get all the properties except b from myObject.

b is destructured earlier, so it’ll be omitted from noB.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *