Created
October 4, 2018 14:25
-
-
Save hg-pyun/c8fc0b1e058afd51343d6ed077818da0 to your computer and use it in GitHub Desktop.
iterator.01.js
This file contains 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
/* array */ | |
let iterable = [10, 20, 30]; | |
for (let value of iterable) { | |
console.log(value); // 10 20 30 | |
} | |
/* string */ | |
let iterable = "boo"; | |
for (let value of iterable) { | |
console.log(value); // "b" "o" "o" | |
} | |
/* Typed Array */ | |
let iterable = new Uint8Array([0x00, 0xff]); | |
for (let value of iterable) { | |
console.log(value); // 0 255 | |
} | |
/* Map */ | |
let iterable = new Map([["a", 1], ["b", 2], ["c", 3]]); | |
for (let entry of iterable) { | |
console.log(entry); // [a, 1] [b, 2] [c, 3] | |
} | |
for (let [key, value] of iterable) { | |
console.log(value); // 1 2 3 | |
} | |
/* Set */ | |
let iterable = new Set([1, 1, 2, 2, 3, 3]); | |
for (let value of iterable) { | |
console.log(value); // 1 2 3 | |
} | |
/* DOM Collection */ | |
let articleParagraphs = document.querySelectorAll("article > p"); | |
for (let paragraph of articleParagraphs) { | |
paragraph.classList.add("read"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment