lodash object difference code example

Example 1: lodash deep compare two objects

var bob = {"sex":"male","age":21};
var bill = {"sex":"male","age":21};
if(_.isEqual(bob, bill)){
    //we are equal
}else{
	//we are not equal
}

Example 2: lodash get difference between two arrays of objects

var presents = _.intersectionWith(array1, array2, _.isEqual);
var dif = _.differenceWith(array1, array2, _.isEqual);

Example 3: how to collect keys using lodash javascript

import * as _ from 'lodash';

const objectMap = {'key1': 'value1', 'key2': 'value2'};
const allKeys = _.keys(objectMap); //Returns a string[]. Here it will be ['key1','key2'];

Example 4: diff two arrays lodash

_.difference([2, 1], [2, 3]);
// => [1]

Tags:

Misc Example