Javascript index of for multiple values

Viewed 18945

Im having a multdimensional javascript arrays like this.

[
["9", "16", "19", "24", "29", "38"],
["9", "15", "19", "24", "29", "38"],
["10", "16", "19", "24", "29", "38"],
["9", "16", "17", "19", "24", "29", "39"],
["10", "16", "17", "19", "24", "29", "39"],
["9", "15", "21", "24", "29", "38"]

.......
.......
]

Around 40 to be exact

and im having an another array called check with the following values

 [9,10] //This is of size two for example,it may contain any number of elements BUT it only contains elements(digits) from the multidimensional array above

What i want is i need to make the multidimensional array unique based for the check array elements

1.Example if check array is [15] Then multidimensional array would be

[
    ["9", "15", "19", "24", "29", "38"],
   //All the results which contain 15

]

2.Example if check array is [15,21] Then multidimensional array would be

[
    ["9", "15", "21", "24", "29", "38"]
    //simply containing 15 AND 21.Please note previous example has only 15 in it not 21
    //I need an AND not an OR

]

I had tried the JavaScript IndexOf method BUt it is getting me an OR'ed result not AND

Thanks in Advance

4 Answers

This should do it

var checkURL = function (url) {
  var final = false;
  if (url.indexOf('jpg') > -1) {
    final = true
  }

  if (url.indexOf('jpeg') > -1) {
    final = true
  }

  if (url.indexOf('gif') > -1) {
    final = true
  }

  if (url.indexOf('png') > -1) {
    final = true
  }

  return final
}

Related