React,Node,JQuery,js
[javascript] Json Key 가져오기 #keys #getOwnPropertyNames
bryan.oh
2020. 12. 18. 23:51
반응형
JS 의 json key 가져오기
Object.keys()
var jsn = { a : 'hello~', b : 'bryan' };
var keys = Object.keys(jsn);
console.log(keys)
["a", "b"]
Object.getOwnPropertyNames()
var jsn = { a : 'hello~', b : 'bryan' };
var keys = Object.getOwnPropertyNames(jsn);
console.log(keys)
["a", "b"]
비표준 브라우저 호환 ( explorer 9 이하 )
var jsn = { a : 'hello~', b : 'bryan' };
for( var k in jsn ) {
console.log(k + ":" + jsn[k]);
}
a:hello~
b:bryan
728x90
반응형