arr.forEach(function (element, index, arr) { console.log(index, element, arr) }) // The above code can be written using arrow function arr.forEach((element, index, arr) => { console.log(index, element, arr) }) // The above code can be written using arrow function and explicit return arr.forEach((element, index, arr) => console.log(index, element, arr)) let sum = 0; const numbers = [1, 2, 3, 4, 5]; numbers.forEach(num => sum += num) console.log(sum)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter