In other words, I want to clean objects by dropping most of their keys.
Say a third party API returns JSON with a large number of of attributes you don't care about.
obj = {
name: ...,
id: ...,
description: ...,
blah: ...,
bloop: ...,
blip: ...,
... 12 others
}
But you're only interested in, say, id
and name
.
I know there's spread syntax object destructuring that allows me to put these into separate variables.
const { id, name } = obj
Is there a way to transform obj
into a new object that looks like the following without explicitly accessing every key and value and making an object out of those?
newObj = {
id: ...,
name: ...
}
I'm curious if there's a one-liner I can put into map
to transform a whole array of these objects.