check fpr multiple values in an array jquery 1

check fpr multiple values in an array jquery

function containsAll(needles, haystack){ 
  for(var i = 0; i < needles.length; i++){
     if($.inArray(needles[i], haystack) == -1) return false;
  }
  return true;
}

containsAll([34, 78, 89], [78, 67, 34, 99, 56, 89]); // true
containsAll([34, 78, 89], [78, 67, 99, 56, 89]); // false
containsAll([34, 78, 89], [78, 89]); // false

Here is what the above code is Doing:
1. The containsAll function takes two arguments: an array of needles and an array of haystack.
2. The for loop iterates through the needles array.
3. The $.inArray function checks if the current needle is in the haystack array.
4. If the needle is not in the haystack array, the function returns false.
5. If the needle is in the haystack array, the function returns true.

Similar Posts