:::: 개발 ::::/::: JSCRIPT :::

스크립트 오브젝트 키/벨류 루프 Object for key value

nayha 2019. 4. 24. 17:18
ECMAScript 5:
No, its not possible with objects.

You should either iterate with for..in, or Object.keys, like this

for (var key in dictionary) {
    // check if the property/key is defined in the object itself, not in parent
    if (dictionary.hasOwnProperty(key)) {           
        console.log(key, dictionary[key]);
    }
}

이것저것해도 안되었는데 저걸로 하니 되었음 ㅎㅎ

오브젝트 형태는

Car : {
	hyun : 'h',
    kia	:'k',
    carList : null
}

 

누군가 도움이 되길..

반응형