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
const collect = require( 'collect.js' );
let array = [ "a" , "b" , "c" , "d" , "e" ];
let arr = [ "a" , "b" , "q" ];
let collec1 = collect(array);
let collec2 = collect(arr);
let aa = collec1.diffAssoc(collec2)
console.log( "Output : " )
console.log(aa.all())
|
Output:
Example 2: When object of key-value pair is given.
Javascript
const collect = require( 'collect.js' );
let obj1 = { "a" : 1, "b" : 12, "c" : 3 };
let obj2 = { "a" : 12, "d" : 2, "c" : 3 };
let collec1 = collect(obj1);
let collec2 = collect(obj2);
let aa = collec1.diffAssoc(collec2)
console.log( "Output : " )
console.log(aa.all())
|
Output:
Last Updated :
29 Jul, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...