I've been struggling with finding an Javascript equivalent of Python's "for x in y". For instance, I want to push numbers that are even to an empty array, but I don't know how to script the code to do so. I've been doing this:
var numbers = [ 1, 2, 3, 4, 5]
var even = []
for(var x = 0; x < numbers.length; x++){
if(x % 2 == 0){
even.push(x)
}
}
same thing for strings too if numbers were instead strings:
var numbers = [ "one", "two", "three"]
var even = []
for(var x = 0; x < numbers.length; x++){
if(x == "two"){
even.push(x)
}
}
i noticed any time I typed it up, it only showed x as the index of the array, but I want to access the elements.