0

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?

0

3 Answers 3

3

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)
      {
         //
         //
      }
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is right but I want to exit both for loop if value is equal
0
var val='your value';
for(var i=0;i<arrayList.length;i++)
{
if(arrayList[i].indexOf(val)>-1){
// do something
// and break
}
}

Comments

0

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');
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.