I have this array
const array = [1, 3, 6];
and this object
const obj = {
1: {id: 1, foo: 'a', ...},
2: {id: 2, foo: 'b', ...}
3: {id: 3, foo: 'c', ...},
4: {id: 4, foo: 'd', ...},
5: {...},
6: {...}
... // up to 1000 key/value paris
};
I wonder how to filter the obj with the keys in the array.
One way would be
obj.filter(elem => elem.id...);
But that iterates through all the elements in the obj, eventhough there are just three elements in the array.
Better would be to iterate over the array, but
array.filter(elem => elem === obj.id ...);
then only returns the elements from the array(meaning, 1, 3, 6).
What I need is an array looking like
const result = ['s', 'b', 'c', 'd'];
What is the best way to do this?
result = ['foo', 'bar']?idas key?idis thekey,fooandbar? Additionally, will there be any values in the array that does not exist in theobj?