[JS] for...of 사용시 인덱스를 사용하고 싶을 때

SINGING BIRD·2023년 4월 18일

[index, item] 으로 배열로 묶어주고,
items.entries() 함수를 추가해주면 됩니다.

// 일반 사용

for(const item of items) {
// ...
}


// index 사용하고 싶을 때

for(const [index, item] of items.entries() {
// ...
}
profile
good things take time

0개의 댓글