Check if an array contains any element of another array in JavaScript

后端 未结 26 1749
礼貌的吻别
礼貌的吻别 2020-11-22 08:48

I have a target array [\"apple\",\"banana\",\"orange\"], and I want to check if other arrays contain any one of the target array elements.

For example:

26条回答
  •  天命终不由人
    2020-11-22 08:53

    I came up with a solution in node using underscore js like this:

    var checkRole = _.intersection(['A','B'], ['A','B','C']);
    if(!_.isEmpty(checkRole)) { 
         next();
    }
    

提交回复
热议问题