Skip to content
Advertisement

JavaScript, filter array of objects by a specific key’s value

I am trying to find the best way to filter my array of objects with specific key’s string. Basically what I am trying to achieve is to get the objects which contain "Type":"Blue". Here is my data:

JavaScript

Advertisement

Answer

You could use the filter() method. See the snippet below, as well as a definition of the method from MDN:

The filter() method creates a new array with all elements that pass the test implemented by the provided function.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement