Simply put, I aim to streamline objects by discarding unnecessary keys.
Imagine a scenario where a third party API sends back JSON data with numerous attributes that hold no importance to you.
obj = {
name: ...,
id: ...,
description: ...,
blah: ...,
bloop: ...,
blip: ...,
... and 12 others
}
However, your only focus lies on certain attributes like id
and name
.
I'm aware of object destructuring that allows me to extract these specific attributes into separate variables.
const { id, name } = obj
Is there a way to convert the original obj
into a new object resembling the following without manually accessing each key-value pair?
newObj = {
id: ...,
name: ...
}
I'm interested in discovering if there's a succinct one-liner solution that can be utilized within a map
function to transform an entire array of such objects.