I have an object:
var obj = { a: 'test1', b: 'test2', c: 'test3', d: 'test4', e: 'test5', f: 'test6', g: 'test7', h: 'test8' }
I want to get result:
res = { a: 'test1', c: 'test3', d: 'test4' }
What is the fastest way to do it?
I have an object:
var obj = { a: 'test1', b: 'test2', c: 'test3', d: 'test4', e: 'test5', f: 'test6', g: 'test7', h: 'test8' }
I want to get result:
res = { a: 'test1', c: 'test3', d: 'test4' }
What is the fastest way to do it?
Directly access the fields:
res = {a: obj.a, c: obj.c, d: obj.d};
i think you want to delete key-value pair from the object so for that here's the solution
delete obj[b];
delete obj[e];
or you can use lodash pick
var _ = require('lodash')
_.pick( obj, [a, c, d] )
or create a new Object
var final = {a: obj.a, c: obj.c, d: obj.d}