Question: I have 2 values, I want to filter those values ​​in my data. How can I do it?

I want to filter the ids 1 and 2.

```
    data: [
            {id: 1, name: "Carl", city: "New York"},
            {id: 2, name: "Anna", city: "New York"},
            {id: 3, name: "Carl", city: "Sydney"}
        ]

    filterValue: [1, 2]

```

Answer: 
Make a hash map out of `data` with `id` as key.

```js
let data = [
        {id: 1, name: "Carl", city: "New York"},
        {id: 2, name: "Anna", city: "New York"},
        {id: 3, name: "Carl", city: "Sydney"}
    ];
let map1 = new Map(data.map(e=>[e.id,e]));
let filterValue = [1, 2];
let output = filterValue.map(e=>map1.get(e));
console.log(output);
```
You can use this utility function, which takes the array of values to filter and the key of the object to filter by:

```js
const data = [{ id: 1, name: 'Carl', city: 'New York' }, { id: 2, name: 'Anna', city: 'New York' }, { id: 3, name: 'Carl', city: 'Sydney' }]

const filterData = (d, f, k) => data.filter(o => f.includes(o[k]))

console.log(filterData(data, [1, 2], 'id'))
console.log(filterData(data, ['Carl'], 'name'))
```