Skip to content

isEqual

The isEqual function compares two values to determine if they are equivalent in structure and content, including objects, arrays, and primitive types.

Syntax

typescript
isEqual(value1, value2): boolean

Parameters

NameTypeDescription
value1anyFirst value to compare.
value2anySecond value to compare.

Return

TypeDescription
booleanReturns true if the values are equivalent, otherwise false.

Examples

typescript
isEqual({ a: 1 }, { a: 1 }); // true
isEqual([1, 2], [1, 2]); // true
isEqual({ a: 1 }, { a: 2 }); // false
isEqual([1, 2], [2, 1]); // false
isEqual(5, 5); // true
isEqual('abc', 'abc'); // true

Notes

  • Performs deep equality comparison for objects and arrays.
  • May not work correctly with objects that have non-enumerable properties or symbols.

References

Released under the MIT License.