See the Pen for of by nilgi (@nilgi) on CodePen.
문자 반복
<p id="fo1"></p>
<script>
const name = "Tistory";
let text = "";
for (const x of name) {
text += x;
}
document.getElementById("fo1").innerHTML = text;
</script>
배열 반복
<p id="fo2"></p>
<script>
const name2 = ["T", "i", "s", "t", "o", "r", "y"];
let text2 = "";
for (const x2 of name2) {
text2 += x2;
}
document.getElementById("fo2").innerHTML = text2;
</script>
new Set 반복
<p id="fo3"></p>
<script>
const name3 = new Set(["T", "i", "s", "t", "o", "r", "y"]);
let text3 = "";
for (const x3 of name3) {
text3 += x3;
}
document.getElementById("fo3").innerHTML = text3;
</script>
map 반복
<p id="fo4"></p>
<script>
const pc = new Map([
["cpu", 250000],
["ram", 150000],
["gpu", 500000]
]);
let text4 = "";
for (const x4 of pc) {
text4 += x4 + "<br/>";
}
document.getElementById("fo4").innerHTML = text4;
</script>