remove a object name from spread operator code example
Example 1: remove a object name from spread operator
let obj = {foo: 1, bar: 2, baz: 3}
function removeProperty(obj, propertyName) {
let newObj = {...obj};
delete newObj[propertyName];
return newObj;
}
console.log(removeProperty(obj, 'foo'));
Example 2: remove a object name from spread operator
+-----------------------------------+
| Browser | delete | destructure |
+---------+-----------+-------------+
| Chrome | 3,229,791 | 1,993,256 |
| Safari | 1,186,679 | 1,872,396 |
+---------+-----------+-------------+
Example 3: remove a object name from spread operator
let obj = {foo: 1, bar: 2, baz: 3}
function removeProperty(obj, propertyName) {
let { [propertyName]: _, ...result } = obj
return result
}
console.log(removeProperty(obj, 'foo'));