Categories
JavaScript Answers

How to loop through an array without using array size with Node.js and JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *