javascript

How to List Out Every Array Element in Javascript


In this article, you will learn how to list out every array element in Javascript.

Let’s say you have an array named ‘a’ with elements “red”, “green”, “blue”.

var a = ["red", "green", "blue"];

In order to list out every array element, you can use the forEach() method. In this example, you will be executing the console.log() function on every array element.

var a = ["red", "green", "blue"];

a.forEach(element => console.log(element));
// => "red"
// => "green"
// => "blue"

Note: The forEach() method functions by executing a function on each array element.


Share on social media

//