Dev-/java script, jQuery, Ajax
자바스크립트 배열 리터럴의 요소, 프로퍼티의 차이점
thiago6
2019. 4. 28. 22:14
let arr = ['a', 'b', 'c'];
arr.name = 'joon';
arr.school = 'banchon';
/**
* arr.length는??? : 3
*
* 배열도 __proto__로 Object를 가지기 때문에
* 프로퍼티도 가질 수 있다.
* but 프로퍼티 != 배열의 요소
*/
모든 '요소 출력'
for (let i = 0; i < arr.length; i++) {
console.log('arr[' + i + '] = ' + arr[i]);
}
모든 '프로퍼티' 출력
for (let property in arr) {
console.log('property:' + property + ', ' + 'arr[' + property + '] = ' + arr[property]);
}