To compare arrays in JavaScript, we use the JSON.stringify
method.
For instance, we write
const isSame = JSON.stringify(a1) === JSON.stringify(a2);
to convert arrays a1
and a2
to JSON strings with JSON.stringify
.
And then we compare the strings with ===
.