VOOZH about

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

⇱ Collect.js whereInstanceOf() function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js whereInstanceOf() function

Last Updated : 16 Oct, 2020

The whereInstanceOf() function is used to filter input with a given class type.  In JavaScript, the array is first converted to a collection and then the function is applied to the collection.

Syntax: 

data.whereInstanceOf('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 whereInstanceOf() function in collect.js
Example 1: Here in this example, we take a collection and then using the whereInstanceOf() method we have returned filtered collection using the key.

Output: 

[
 new Books('Pride and prejudice'),
 new Books('The Great Gatsby'),
]

Example 2: Same thing we have done here as the above example.

Output: 

[
 new Name('Mohan'),
]


References: https://collect.js.org/api/whereinstanceof.html

Comment
Article Tags: