DEV Community

Ankit Kanojia
Ankit Kanojia

Posted on

2

Answer: For-each over an array in JavaScript?

As per the new updated feature ECMAScript 6 (ES6) and ECMAScript 2015, you can use the following options with loops:

for loops

for(var i = 0; i < 5; i++){
  console.log(i);
}

// Output: 0,1,2,3,4

for...in loops

let obj = {"a":1, "b":2}

for(let k in obj){
  console.log(k)
}

// Output:

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up