My json object looks like this
Object
A:Object
B:Object
C:Object
D Object
E:Object
F:Object
__proto__:Object
I want to get only D and E from this json object based on key. New json object should only include D and E. how to acheive this?
Try this:
function copyObjectProps(source, keys) {
let newObject = {}
keys.forEach(function(key) {
newObject[key] = source[key]
})
return newObject
}
And use it like:
let filteredObject = copyObjectProps(yourObject, ['D', 'E'])
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