VOOZH about

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

⇱ Collect.js | intersect() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js | intersect() Function

Last Updated : 11 Jun, 2020

The intersect() function is used to remove the value in the main collection which is not present in the given collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.


Syntax: 

data.intersect('x')

Parameters: This function accept a single parameter as mentioned above and described below:

  • x: Hold a collection that will intersect with the main collection .

Return Value:  Returns a modified or you can say intersected collection.
 

Below examples illustrate the intersect() function in collect.js
Example 1: Here in this example, we take a collection and then using the intersect() function take a new collection with which the value are intersected and a modified collection is returned.

Output:

[ 1, 2, 3 ]

Example 2:

Output:

[ 8, 6, 5 ]

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

Comment
Article Tags: