Considering follow code
const filterArray = ['a', 'b']
const objectToBeFilter = {
a: {
ab: 'ab',
ac: 'ac',
ad: 'ad'
},
b: {
bb: 'bb',
bc: 'bc',
bd: 'bd'
},
c: {
cb: 'cb',
cc: 'cc',
cd: 'cd'
}
}
const resultWantToGet = [
a: {
ab: 'ab',
ac: 'ac',
ad: 'ad'
},
b: {
bb: 'bb',
bc: 'bc',
bd: 'bd'
}
]
FilterArray is a array to be used as a filter index, objectToBeFilter is a object which I want to handle. How to use filterArray to filter objectToBeFilter and then convert it to a array resultWantToGet?
aandb, which is a syntax error. Do you want an array or new object?[ { ab: 'ab', ac: 'ac', ad: 'ad' }, { bb: 'bb', bc: 'bc', bd: 'bd' } ](without the keys). See answer below if that's what you are looking for.