Checking whether certain item is in certain array using javascript -
i have 10 different arrays. each array has different numbers.
array1 = [1,2,3,4,5] array2 = [6,7,8,9,10] ... array 10 = [51,52,53,54]
let's pass in 7. want know array , want return array number. in case going 2.
should write switch statement each array? appreciate in javascript.
try:
var arrays = [array1, array2, ..., array10]; for(var i=0; i<arrays.length; ++i) { if (arrays[i].indexof(value) != -1) { console.log('found in array' + (i+1)); } }
Comments
Post a Comment