In pure JavaScript is it possible to create a loop in the form of
for item in array
{
alert(item)
// do stuff
}
instead of
for (var i = 0; i < array.length; i++)
{
alert(array[i])
// do stuff
}
In pure JavaScript is it possible to create a loop in the form of
for item in array
{
alert(item)
// do stuff
}
instead of
for (var i = 0; i < array.length; i++)
{
alert(array[i])
// do stuff
}
One option would be to use a let...of
loop
for (let item of array) {
alert(item);
}
Another option would be to use a forEach
loop
array.forEach(function(item){
alert(item);
});
You can find more information here.