how to filter array objesct in express node js 1

how to filter array objesct in express node js

var data = [
  // the array to be filtered
];

var filteredArray = data.filter(item => (item.name === req.query.q));

Here is what the above code is Doing:
1. We’re creating an array called data.
2. We’re creating a variable called filteredArray.
3. We’re using the filter() method to filter the data array.
4. We’re using the arrow function to return the items that match the query string.
5. We’re using the req.query.q to get the query string from the URL.

Similar Posts