lundi 7 mai 2018

how can I iterate the elements of an array and show a message when it's in the middle in javascript?

I am a newbie trying to understand the basics of Javascript with some basic exercises but I can't do this one. Any idea of how should I write it instead?

var array5 = [1,2,3,4,5];

for (var i=0; i<array5.length; i++) {
console.log(array5[i]);
  if (array5=[2]) {
  alert("we are in the middle of loop");}
}

PD: by the way, it has to be using the for loop and conditional if.

Thanks!

Aucun commentaire:

Enregistrer un commentaire