I need help trying to get my code to work. I want to be able to loop my arrays and use the if command to make sure the array is there.
arr = ["1","2","3","4"];
for (var i = 0; i < arr.length; i++) {
if (string != arr[i]) {
//do something
}
}
But it does not work. the if command ignores.
var arr = ["150","-75"];
right = righ + "px";
leftpl=left * 1;
if (left < 325){
leftplu = leftpl + 10; leftplus = leftplu + 'px ';
for (var i = 0; i < arr.length; i++) {
if (leftplus+right != arr[i]){
document.getElementById("new").innerHTML=leftplu+'px ' + righ+'px';
}
}
}
or can I put the for loop in the "if (leftplus+right != arr[i])" like "if (leftplus+right != for for (var i = 0; i < arr.length; i++) {arr[i]})"
I apologize, for my poor effort to understand. I'm new to javascript and trying to learn.
leftplu,leftpl, andleftplus(if so you should probably come up with different names, if not you have typos) -- alsorightandrigh?if (leftplus+right != arr[i])-- butleftplusandrightare both strings, so you are essentially sayingif ('50px 60px' != "150")(obviously I made up the numbers in front of px but you get the idea) -- so the code in the if should run everytime and keep overwriting the contents of elementnew. Is that what you see?