Okay here goes...I 'm practicing on arrays. I can manage to pick several items from a list using with the for.Each but when it comes to the for loop I am unable to do so. In the for.each I get 3 6 & 9.
var numbers =[1,2,3,4,5,6,7,,8,9,10];
var colors=["blue", "green", "yellow", "red", "white"];
numbers.forEach(function(color){
if (color%3===0) {
console.log(color);
}
});
my for loop code is shown below what am I doing wrong I get the result undefined everytime I ran the code?
var numbers =[1,2,3,4,5,6,7,,8,9,10];
var colors=["blue", "green", "yellow", "red", "white"];
for( i =0; i<numbers.length; i++ ){
if (numbers%3===0) {
console.log(numbers[i]);
}
}
numbers%3->numbersis an array. This condition will never be true. In order to select individual array items usenumbers[i]%3.