VOOZH about

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

⇱ Collect.js diff() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js diff() Function

Last Updated : 15 Oct, 2024

The diff()function compares the main collection against the given collection and returns the values that are in the original collection but not in the given collection.

Syntax:

data.diff(collection)

Parameters:

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

  • collection: Hold the collection that will be compared with the main collection.

Return Value:

Returns a new collection with difference between collection items.

Example 1: Here in this example, we take a collection and then using the diff() function and return the value not in the new collection.

Output:

Collection { items: [ 3, 4, 6 ] }

Example 2: There is one thing to notice that this function holds a collection, compare with the main collection but only return only those items that are extra in the main collection.

Output:

[ 1 , 2]
Comment
Article Tags: