/*----------------------------------------- * An example of how it should work *----------------------------------------- const obj = { one: 1, two: 2, three: 3, four: 4 } const {one, three, ...rest} = obj console.log(one) // 1 console.log(three) // 3 console.log(rest) // { two: 2, four: 4 } */ // implementation: // obj - the object on which to do the rest operation // props - array of strings, that contain the property names // to be excluded from obj function restifyObject(obj, ...props) { return Object.keys(obj) .reduce((acc, key) => { props.forEach(prop => { if (props.indexOf(key) === -1) acc[key] = obj[key] }) return acc }, {}) } // example const obj = { one: 1, two: 2, three: 3, four: 4 } const {one, three} = obj const rest = restifyObject(obj, 'one', 'three') console.log(one) // 1 console.log(three) // 3 console.log(rest) // { two: 2, four: 4 }