To use Lodash to compare jagged arrays, we use the isEqual
and sort
methods.
For instance, we write
const array1 = [
["a", "b"],
["b", "c"],
];
const array2 = [
["b", "c"],
["a", "b"],
];
const isEqual = _.isEqual(array1.sort(), array2.sort());
to call sort
on each array to return a sorted version of them.
And then we call isEqual
with the sorted array to check if they have the same content.