How to Filter a JavaScript Array of Objects by Key Value?

Estimated read time 1 min read

You can filter a JavaScript array of objects by using the Array.prototype.filter() method and comparing the values of specific keys in each object of the array.

Here’s an example:

const originalArray = [
  {id: 1, name: 'John', age: 25},
  {id: 2, name: 'Jane', age: 32},
  {id: 3, name: 'Jim', age: 41},
  {id: 4, name: 'Jessica', age: 29}

const filteredArray = originalArray.filter(obj => obj.age >= 30);

// Output: [{id: 2, name: 'Jane', age: 32}, {id: 3, name: 'Jim', age: 41}]

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply