Native JavaScript solution
var success = array_a.every(function(val) {
return array_b.indexOf(val) !== -1;
});
You'll need compatibility patches for every
and indexOf
if you're supporting older browsers, including IE8.
Full jQuery solution
var success = $.grep(array_a, function(v,i) {
return $.inArray(v, array_b) !== -1;
}).length === array_a.length;
Uses $.grep
with $.inArray
.
ES2015 Solution
The native solution above can be shortened using ES2015's arrow function syntax and its .includes()
method:
let success = array_a.every((val) => array_b.includes(val))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…