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: 
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'))
```
Use `filter` and `indexOf` to filter values in the array using another array

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

var filterValue = ["Carl"];
console.log(data.filter(function(e) {
  return filterValue.indexOf(e.name) != -1
}))
```