snippet

Determine if two array Javascript are equivalent

If you need to compare two arrays and determine if the two arrays are equivalent, here is a simple function that returns true if the two arrays are equal and false otherwise.
const isEqualArray = (a, b) => JSON.stringify(a) === JSON.stringify(b);

// Return true
isEqualArray(['tomate'], ['tomate']);

// Return false
isEqualArray(['tomate'], ['banana']);
Related snippets