I'm trying to compare two unordered arrays of strings with lodash. I have tried using the isMatch
function but it doesn't seem do what I want. Here's what I have tried:
var arr1 = ['foo', 'bar']
var arr2 = ['bar', 'foo']
_.isEqual(arr1,arr2) //should return true, but instead it returns false
Thanks.
You need to sort()
the arrays to maintain the sequence for comparing it with _.isEqual()
var arr1 = ['foo', 'bar']
var arr2 = ['bar', 'foo']
console.log(_.isEqual(arr1.sort(),arr2.sort()));
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With