Open In App

Lodash _.eq() Method

Lodash _.eq() method is used to find whether the two values are equivalent or not by performing the SameValueZero comparison. It returns true if the values are equivalent. Otherwise, it returns false.

Syntax:

_.eq(value, other);

Parameters:

Return Value:

This method returns true if the values are equivalent, else false.



Example 1: In this example, we are checking whether the given two values are the same or not by the use of the _.eq() method.




// Requiring the lodash library 
const _ = require("lodash"); 
      
// Use of _.eq method
console.log(_.eq("Geeks", "Geeks" ));
console.log(_.eq("Geeks", Object("Geeks")));
console.log(_.eq(NaN, NaN));

Output:



true
false
true

Example 2: In this example, we are checking whether the given two objects are the same or not by the use of the _.eq() method.




// Requiring the lodash library 
const _ = require("lodash");
 
// Given values
let object = { 'gfg': 2020 };
let other = { 'gfg': 2020 };
 
// Use of _.eq method
console.log(_.eq(object, object));
console.log(_.eq(object, other));

Output:

true
false
Article Tags :