VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-where-function/

⇱ Collect.js where() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js where() Function

Last Updated : 12 Jan, 2021

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:

  • Key: This parameter holds the key name that defines the value of that key.

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:

Output:

[
 new Year('2025')
]

Reference: https://collect.js.org/api/where.html

Comment
Article Tags: