Jquery – check if multiple items inArray


Is it possible to check if multiple items are contained within an array using jquery's inArray function?

if ($.inArray('foo' && 'bar', array) == -1) {
    // Neither foo or bar in array


Best Solution

With jQuery.inArray, you can (quoting) :

Search for a specified value within an array and return its index (or -1 if not found).

Looking at that documentation page, it doesn't seem you can pass more than one value to that function.

So, why not call that function twice : one time for 'foo', and one time for 'bar' :

if ($.inArray('foo', array) == -1 && $.inArray('bar', array) == -1) {
    // Neither foo or bar in array