In this trick, you will see how you can use a filter() function with a javascript array and get a value from the array based on the filters.
Filtering an array is useful when you’re working with multiple columns of corresponding data. In this case, you can include and exclude data based on any characteristic that describes a group in your array.
To filter an array, use the filter() function.
Example 1:
Output:
[ { make: 'Mercedes', class: 'Classic' }, { make: 'Honda', class: 'Classic' } ]
You can also use filter() function together with Boolean to remove all null or undefined values from an javascript array.
Example 2:
Output:
[ { make: 'Mercedes', class: 'Classic' } ]
Being Tricky 😉