JavaScript: a quick solution to check if two arrays are equal

JavaScript: a quick solution to check if two arrays are equal

In JavaScript there is a quick solution to check if two arrays are equal.

In JavaScript there is a quick solution to check if two arrays are equal.

We can use JSON.stringify() like so:


'use strict';

const areArraysEqual = (a, b) => {
    if(!Array.isArray(a) || !Array.isArray(b)) {
        return false;
    }
    return JSON.stringify(a) === JSON.stringify(b);
};