underscore.js - Determine if all values in an array of arrays match

后端 未结 9 2127
迷失自我
迷失自我 2020-12-20 11:30

I have an array of arrays, which looks something like this:

[[\"Some string\", \"Some other string\"],[\"Some third string\", \"some fourth string\"]]
         


        
9条回答
  •  佛祖请我去吃肉
    2020-12-20 12:03

    Use underscore to determine the difference between the two, and check the length of the array. An easy way to do this would be:

    _.isEmpty(_.difference(array1, array2)) && _.isEmpty(_.difference(array2, array1))
    

    This will return true if they are the same and false if they are not.

提交回复
热议问题