I am struggling to troubleshoot my code. My goal is to iterate through arrays and use the if statement to check if the array exists.
arr = ["1","2","3","4"];
for (var i = 0; i < arr.length; i++) {
if (string != arr[i]) {
//do something
}
}
Unfortunately, it's not working as expected. The if statement seems to be disregarded.
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';
}
}
}
Alternatively, can I place the for loop directly inside the "if (leftplus+right != arr[i])" like "if (leftplus+right != for for (var i = 0; i < arr.length; i++) {arr[i]})"
I must apologize for my limited understanding. I am new to JavaScript and still in the learning process.