[javascript] Object.entries()

sunny·2020년 12월 30일
0
post-thumbnail

Object.entries()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

객체가 가지고 있는 모든 속성을 값을 배열로 반환한다.

const obj = {
  a: 'hi',
  b: 100
};

Object.entries(obj);

결과

(2) [Array(2), Array(2)]

0: (2) ["a", "hi"]
1: (2) ["b", 100]

for문으로 출력

for (const [key, value] of Object.entries(obj)) {
  console.log(`${key} : ${value}`);
}

결과

a : hi
b : 100
profile
blog 👉🏻 https://kimnamsun.github.io/

0개의 댓글