Created
July 26, 2016 11:36
-
-
Save MikSDigital/29d5a0e0f1c2b3083afb0588b0b9610e to your computer and use it in GitHub Desktop.
Printing the contents of an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logArrayElements(element, index, array) { | |
console.log('a[' + index + '] = ' + element); | |
} | |
// Notice that index 2 is skipped since there is no item at | |
// that position in the array. | |
[2, 5, , 9].forEach(logArrayElements); | |
// logs: | |
// a[0] = 2 | |
// a[1] = 5 | |
// a[3] = 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach