I have a javascript object like this,
{
apple: { .... },
orange: { ... },
mango: { ... },
jackfruit: { ... }
}
and I want to grenerate a new object from this object. I want values of cetain keys only, like ['mango', apple' ]
Is there any filter function to filter these items from this object using this array?
My resulting object should be like
{
mango: { ... }
apple: { ... }
}
Object.keys(obj).filter(r => ['mango','apple'].indexOf(r) > -1).map(i => obj[i]);should be enough.