![]() |
VOOZH | about |
The where() function is used to filter the collection by a given key or value contained within the given array. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.
Syntax:
data.where('key')
Parameters: This function accepts a single parameter as mentioned above and described below:
Return value: Return the collection with a key value that was mentioned.
Below examples illustrate the where() function in collect.js:
Example 1: Here in this example, we take a collection and then using the where() method we have returned filtered collection using the key.
Output:
[
{ Book: 'Begin Python', price: 1000 },
{ Book: 'Learn the DEV', price: 1500 }
]
Example 2: