dev.Log
배열의 순회 본문
1. forEach 사용
var array = [1,2,3,4,5];
data.forEach(function(value) {
console.log(value);
});
2. for in 사용 - 상위에 있는 객체 내용까지 가져오게됨 (Array에서 사용 지양)
Array.prototype.getIndex = function() {};
for(let idx in array) {
console.log(array[idx]); //1 2 3 4 5 function(){}
}
3. for of 사용 (배열만을 위한 것)
for(let value of array) {
console.log(value);
}
'<FRONTEND>' 카테고리의 다른 글
from 메서드로 진짜 배열 만들기 (0) | 2022.12.17 |
---|---|
Spread Operator - 배열의 복사 (0) | 2022.12.17 |
immutable(불변) array (0) | 2022.12.17 |
Debouncing 과 Throttling (0) | 2022.10.24 |
웹 성능 개선하기 (0) | 2022.09.30 |
Comments