Skip to content

Instantly share code, notes, and snippets.

@ecowden
Last active January 18, 2016 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecowden/b99d940205a67f7ebdda to your computer and use it in GitHub Desktop.
Save ecowden/b99d940205a67f7ebdda to your computer and use it in GitHub Desktop.
Use of a JavaScript Array as an `iterable` in a `for-of` loop
const assert = require('assert')
const numbers = [0, 2, 4, 6, 8]
let sum = 0
// We can loop through “iterables” with the new “for-of” loop:
for (let n of numbers) {
sum += n
}
assert.equal(sum, 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment