Compare 2 array's elements against each other and return count JavaScript

后端 未结 3 661
花落未央
花落未央 2021-01-14 17:45

I have 2 arrays that I need to compare against each other and return the count of the same.

Example: compare array1 [abcd] against array2 [adce]. Return would be 2,1

3条回答
  •  逝去的感伤
    2021-01-14 18:22

    There is a JS library UnderscoreJS which provides a number of useful method for processing JavaScript arrays. You can use its difference method:

    _.difference(['a','b','c','d'], ['a','d','c','e']) // returns ["b"] 
    

提交回复
热议问题