Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js spread exclude property

//// EXCLUDE OBJECT PROPERTY USING THE spread OPERATOR ////

const firstObject = {id: 0, firstName: 'John', age: 77 };
// take every property except age:
const {age, ...secondObject} = firstObject;

console.log(firstObject);
console.log(secondObject);
// { id: 0, firstName: 'John', age: 77 }
// { id: 0, firstName: 'John' }
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #js #spread #exclude #property
ADD COMMENT
Topic
Name
8+2 =