This is how I've been doing it:
var props = { id: 1, name: 'test', children: [] }
//copy props but leave children out
var newProps = { ...props }
delete newProps.children
console.log(newProps) // { id: 1, name: 'test' }
Is there a cleaner, simpler way?
You could use a destructuring assignment:
var props = { id: 1, name: 'test', children: [] }
var {children:_, ...newProps} = props;
console.log(newProps) // { id: 1, name: 'test' }
console.log(_) // [] - as an "empty" placeholder
(with the same rest/spread properties proposal for ES7 that you were already using)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With