Is there a way I can destructure object into its arbitrary property value and the rest of the properties?
So far, my attempts didn't give much success:
const x = {a:1, b:2, c:3};
const obj2pieces = (obj,propName) => {
({propName,...rest} = obj);
return [propName, {...rest}]
};
console.log(obj2pieces(x, 'a')); // [undefined,{"a":1,"b":2,"c":3}]
What I would like to get instead is [1,{"b":2,"c":3}]
.