Object.entries, Object.values

jathazp·2022년 2월 27일
0

Object.entries

Object.entries() 메서드는 주어진 객체 자체의 enumerable 속성 [key, value] 쌍의 배열을 반환한다.

const object1 = {
  a: 'somestring',
  b: 42
};

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

// expected output:
// "a: somestring"
// "b: 42"

Object.values

Object.values() 메소드는 전달된 파라미터 객체가 가지는 속성의 값들로 이루어진 배열을 리턴한다.

const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.values(object1));
// expected output: Array ["somestring", 42, false]

0개의 댓글