자바스크립트 객체에 속성 추가하기. Object.defineProerty()
let sampleObj = [
{id:1, name:'kangAgee', key:183 },
{id:2, name:'GoyangE', key:171 },
{id:3, name:'toKi', key:169 },
];
for(let i=0; i<sampleObj.length; i++){
Object.defineProperty(sampleObj[i], 'job', {
value : 'developer'
})
} // END for
console.log('sampleObj ::: ', sampleObj);
참고 :
책 : 러닝자바스크립트 : ES6로 제대로 입문하는 모던 자바스크립트 웹 개발
객체 기본 : https://developer.mozilla.org/ko/docs/Learn/JavaScript/Objects/Basics
Object.defineProperty() :
1) https://runebook.dev/ko/docs/javascript/global_objects/object/defineproperty
2) https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
728x90
300x250