JS: Test Array Equality

By Xah Lee. Date: . Last updated: .

Test Array Equality by Content

Array equality test by their references

use Triple Equal Operator.

// 2 arrays having same reference. triple equal return true
const xaa = [3, 4];
const xbb = xaa;
console.log(xaa === xbb);
// 2 arrays having same content. triple equal return false
console.log(([3, 4] === [3, 4]) === false);

There's no builtin way to test array items equality in JavaScript.

Test Array Equality by Comparison as JSON String

JavaScript. Array