JavaScript Loop/Iterate Array

Dec 12, 2019
const items = ['Apple', 'Pear', 'Orange']

for index

for (var i=0; i<items.length; i++) {    console.log(items[i])}

forEach

items.forEach(item => {    console.log(item)})

with index

items.forEach((item, index) => {    console.log(item, index)})

for ... of

for (const item of items) {    console.log(item)}

with index

for (const [index, item] of items.entries()) {  console.log(item, index)}

NOTE: Don't use for ... in as it is used to iterate object/dict.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.