Sometimes, we want to loop through an array without using array size with Node.js and JavaScript.
In this article, we’ll look at how to loop through an array without using array size with Node.js and JavaScript.
How to loop through an array without using array size with Node.js and JavaScript?
To loop through an array without using array size with Node.js and JavaScript, we use the forEach
method.
For instance, we write
const myArray = ["1", "2", 3, 4];
myArray.forEach((value) => {
console.log(value);
});
to call myArray.forEach
with a callback to loop through element.
We get the element being looped through with value
.
Conclusion
To loop through an array without using array size with Node.js and JavaScript, we use the forEach
method.