Node JS Foreach Loop Array Example

By Hardik Savani November 5, 2023 Category : Node JS

Hello all! In this article, we will talk about node js foreach loop array. In this article, we will implement a foreach loop node.js array. Here you will learn for loop in node js array. This post will give you simple example of for loop in node js json array.

i will give you two simple example with node foreach loop. let's see both example one by one.

Example 1:

const myArray = ['PHP', 'Laravel', 'Angular', 'React', 'Node'];

myArray.forEach(element => {

console.log(element);

});

Output:

PHP

Laravel

Angular

React

Node

Example 2:

const myArray = [1, 2, 3, 4, 5, 7];

myArray.forEach((element, index) => {

console.log('Key:' + index + ' Value:' + element);

});

Output:

Key:0 Value:1

Key:1 Value:2

Key:2 Value:3

Key:3 Value:4

Key:4 Value:5

Key:5 Value:7

i hope it can help you...

Tags :
Shares