DEV Community

Cover image for 7 Ways of looping through an array in JavaScript.
Peter Wainaina
Peter Wainaina

Posted on

7 Ways of looping through an array in JavaScript.

Simply put, an array is a collection of same data type items stored in contiguous(consecutive; following each other) memory locations.

More often than not, arrays are used during programming for a couple of reasons: storing user information, storing some identification attributes, just to mention but a few.

It becomes necessary at some point in time for a programmer to access this stored data and I have highlighted 7 ways in which one can easily do so using some JavaScript code snippets:

  1. Looping through an array using for loop.

Image description

  1. Looping through an array using while loop.

Image description

  1. Looping through an array using do...while loop.

Image description

  1. Looping through an array using map() method.

Image description

  1. Looping through an array using for...of.

Image description

  1. Looping through an array using for...in.

Image description

  1. Looping through an array using forEach() method.

Image description

I hope the article was helpful. Happy coding!

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay