Thursday, June 11, 2026
HomeLanguagesJavascriptCollect.js diffAssoc() Function

Collect.js diffAssoc() Function

The diffAssoc() function is used to compare two given collection and returns the values and their indices which are not present in the given collection. If key-value pair is given in the collection it compares and returns on the basis of keys specified.

Syntax:

diffAssoc( collection );

Parameters:

  • collection: It is the collection given whose values are to be compared from the original array.

Return Value: It returns the values and their indices which are not present in the given collection.

Example 1: When an array is given as a collection

Javascript




// Importing the collect.js module.
const collect = require('collect.js');
let array = ["a", "b", "c", "d", "e"];
let arr = ["a", "b", "q"];
  
// Making the collec1
let collec1 = collect(array);
let collec2 = collect(arr);
  
// Using diffAssoc() Function
let aa = collec1.diffAssoc(collec2)
  
// The output is so because c, d, e
// are not present in collec2 
// But are present in collec1
console.log("Output : ")
console.log(aa.all())


Output:

Example 2: When object of key-value pair is given.

Javascript




// Importing the collect.js module.
const collect = require('collect.js');
let obj1 = { "a": 1, "b": 12, "c": 3 };
let obj2 = { "a": 12, "d": 2, "c": 3 };
  
// Making the collec1
let collec1 = collect(obj1);
let collec2 = collect(obj2);
  
// Using diffAssoc() Function
let aa = collec1.diffAssoc(collec2)
  
// The output is so because a whose 
// value is 1 and b whose value is 12 
// because are not present in collec2 
// But are present in collec1
console.log("Output : ")
console.log(aa.all())


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS