Skip to content

equalsDeep

Recursive structural array equality.

Two arrays are equal when they have the same length and each pair of elements at the same index is structurally equal:

  • Arrays recurse with equalsDeep.
  • Plain objects recurse key-by-key with structural comparison.
  • Date instances are compared by their epoch value.
  • All other values use strict equality (===), which means NaN !== NaN and special objects (Map, Set, RegExp, Promise, class instances\u2026) are compared by reference.

For positional one-level comparison use equalsShallow. For order-independent comparison use equalsUnordered.

Available since v2.0.0

import { equalsDeep } from '@helpers4/array';
// or, from the all-in-one package (same code, one install):
import { equalsDeep } from 'helpers4/array';
equalsDeep<T>(arrA: readonly T[], arrB: readonly T[]): boolean
ParameterTypeDescription
arrAreadonly T[]First array to compare
arrBreadonly T[]Second array to compare

boolean — true if arrays are deeply equal, false otherwise.

Deeply compares two arrays including nested structures.

equalsDeep([[1, 2], [3]], [[1, 2], [3]])
// => true

Returns false when nested arrays differ.

equalsDeep([[1, 2]], [[1, 3]])
// => false

View source on GitHub