const obj = {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
f: 6,
}
{a: 1, d: 4, e: 5, f: 6}
const {a, d, e, f, ...otherObj} = obj;
const anotherObj = {a, d, e, f};
const keys = [ 'a', 'd', 'e', 'f' ];
.const obj1 = {};
const obj2 = {};
for (const k in obj) {
if (obj.hasOwnProperty(k)) {
(keys.indexOf(k) > -1 ? obj2 : obj1)[k] = obj[k];
}
}
const partition = (data, f) =>
Array.prototype.reduce.call(
data,
(acc, n, i, a) => (
acc[+!!f(n, i, a)].push(n),
acc
),
[ [], [] ]
);
const [ obj1, obj2 ] = partition(
Object.entries(obj),
n => keys.includes(n[0])
).map(Object.fromEntries);