"자바스크립트 for...in"의 두 판 사이의 차이

5번째 줄: 5번째 줄:
<syntaxhighlight lang='javascript' run>
<syntaxhighlight lang='javascript' run>
const object = { a: 1, b: 2, c: 3 };
const object = { a: 1, b: 2, c: 3 };
for (const k in object) {
for (const key in object) {
   console.log(k, "→", object[k]);
   console.log(key, "→", object[key]);
}
}
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='javascript' run>
<syntaxhighlight lang='javascript' run>
const fruits = ["apple", "banana", "cherry"];
const fruits = ["apple", "banana", "cherry"];
for (const k in fruits) {
for (const idx in fruits) {
   console.log(k, "→", fruits[k]);
   console.log(k, "→", fruits[idx]);
}
}
</syntaxhighlight>
</syntaxhighlight>

2023년 10월 20일 (금) 20:15 판

1 개요

JavaScript for...in
자바스크립트 for...in
const object = { a: 1, b: 2, c: 3 };
for (const key in object) {
  console.log(key, "→", object[key]);
}
const fruits = ["apple", "banana", "cherry"];
for (const idx in fruits) {
  console.log(k, "→", fruits[idx]);
}

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}