Reputation: 5069
I have two arrays
var array1 = ['me','you','our'];
var array2 = ['us','they','all'];
I have another array
var arrayList = [array1, array2]
Now I have one value which I want to compare with each value of each array inside arrayList.
How can we do that?
Upvotes: 0
Views: 2500
Reputation: 5018
Try this...
var yourValue;
for(var i=0;i<arrayList.length;i++)
{
for(var j=0;j<arrayList[i].length;j++)
{
if(arrayList[i][j] == yourValue)
{
//
//
}
}
}
Upvotes: 3
Reputation: 23065
Loop through arrayList
then use indexOf.
var val = 'you';
for(var i = 0; i < arrayList.length; i++){
if(arrayList[i].indexOf(val) !== -1){
alert('match');
}
}
Upvotes: 0
Reputation: 2051
var val='your value';
for(var i=0;i<arrayList.length;i++)
{
if(arrayList[i].indexOf(val)>-1){
// do something
// and break
}
}
Upvotes: 0