I have the following array of objects:
[{id:1, value:100, name:dog ...},
{id:2, value:200, name:cat ...},
{id:3, value:300, name:fish....},
{id:4, value:400, name:mouse ...},
{id:5, value:500, name:snake...}]
I want to filter the object array and keep only two keys, id
and value
to get something like this:
[{id:1, value:100},
{id:2, value:200},
{id:3, value:300},
{id:4, value:400},
{id:5, value:500}]
Currently, I'm traversing through the object array with a for loop and doing a push()
to an empty array with the new variables. Is there an easier way to do this?
I wanted to use Lodash like _.pluck(PetList, 'id', 'value');
but lodash extracts the value only, not the key.