How to use the isEqual function from underscore

Find comprehensive JavaScript underscore.isEqual code examples handpicked from public code repositorys.

underscore.isEqual is a method used to compare two objects and their properties.

255
256
257
258
259
260
261
262
263
264
  console.log(prefix + spaces(indent * 2) + text);
};

var isChild = function (entry1, entry2) {
  return (entry2.length === entry1.length + 1 &&
          _.isEqual(entry1, entry2.slice(0, entry1.length)));
};

var children = function (entry1) {
  return _.filter(entries, function (entry2) {
fork icon0
star icon7
watch icon4

+ 5 other calls in file

320
321
322
323
324
325
326
327
328

// we need a recursive comparison function to bubble up the branch
var recurseCompare = function(commitA, commitB) {
  // this is the short-circuit base case
  var result = options.isEqual ?
    options.isEqual(commitA, commitB) : _.isEqual(commitA, commitB);
  if (!result) {
    return false;
  }
fork icon0
star icon0
watch icon1

+ 20 other calls in file

How does underscore.isEqual work?

_.isEqual() is a method from the Underscore.js library that recursively compares two values and determines if they are equivalent, returning a boolean value. The comparison is based on the value's types and properties, and the method can be customized by passing in a callback function to handle specific cases. For example, the method can handle comparisons of arrays and objects with varying property orders or extra properties, as long as the key-value pairs match in content and order.

5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.isEqual(object, other);
* // => true
*
* object === other;
* // => false
fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
6
const object1 = { a: 1, b: 2 };
const object2 = { a: 1, b: 2 };
const object3 = { a: 1, b: 3 };

_.isEqual(object1, object2); // true
_.isEqual(object1, object3); // false

In this example, _.isEqual is used to compare two objects object1 and object2, which have the same properties and values, so the function returns true. The function is also used to compare object1 and object3, which have different values for the b property, so the function returns false.