📜  Lodash _.isEqual() 方法

📅  最后修改于: 2022-05-13 01:56:32.960000             🧑  作者: Mango

Lodash _.isEqual() 方法

Lodash _.isEqual() 方法在两个值之间执行深度比较以确定它们是否相等。此方法支持比较数组、数组缓冲区、布尔值、日期对象、地图、数字、对象、正则表达式、集合、字符串、符号和类型化数组。

句法:

_.isEqual( value1, value2)

参数:此方法接受上面提到的两个参数,如下所述:

  • value1:要检查的 value1。
  • value2:要检查的 value2。

返回值:此方法返回一个布尔值(如果两个值相等则返回 true,否则返回 false)。

示例 1:

Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = { "a": "gfg" };
  
var val2 = { "a": "gfg" };
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = [1, 2, 3, 4]
  
var val2 = [1, 2, 3, 4]
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = "gfg"
  
var val2 = "gfg"
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = 1
  
var val2 = 1
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = 222
  
var val2 = 323
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));


输出:

The Values are Equal : true

示例 2:对于数组:  

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = [1, 2, 3, 4]
  
var val2 = [1, 2, 3, 4]
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

输出:

The Values are Equal : true

示例 3:对于字符串:  

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = "gfg"
  
var val2 = "gfg"
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

输出:

The Values are Equal : true

示例 4:对于数字:  

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = 1
  
var val2 = 1
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

输出:

The Values are Equal : true

示例 5:

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = 222
  
var val2 = 323
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

输出:

The Values are Equal : false