Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 1.15 KB

object.values-and-object.entries.md

File metadata and controls

40 lines (27 loc) · 1.15 KB

Object.values & Object.entries

Object.values

  • object내의 value 값들을 array 형태로 출력
  • number 형태의 key를 가지고 있는 경우, 해당 숫자의 크기 오름차순으로 array 구성
  • string type의 경우 각각의 단어가 array 형태로 제공
const obj = { x: 'xxx', y: 1 };
Object.values(obj); // ['xxx', 1]

const obj = ['e', 's', '8']; // same as { 0: 'e', 1: 's', 2: '8' };
Object.values(obj); // ['e', 's', '8']

// when we use numeric keys, the values returned in a numerical 
// order according to the keys
const obj = { 10: 'xxx', 1: 'yyy', 3: 'zzz' };
Object.values(obj); // ['yyy', 'zzz', 'xxx']
Object.values('es8'); // ['e', 's', '8']

Object.entries

  • Object.key, Object.values 처럼 [key, value]를 array 한쌍으로 제공
const obj = { x: 'xxx', y: 1 };
Object.entries(obj); // [['x', 'xxx'], ['y', 1]]

const obj = ['e', 's', '8'];
Object.entries(obj); // [['0', 'e'], ['1', 's'], ['2', '8']]

const obj = { 10: 'xxx', 1: 'yyy', 3: 'zzz' };
Object.entries(obj); // [['1', 'yyy'], ['3', 'zzz'], ['10', 'xxx']]
Object.entries('es8'); // [['0', 'e'], ['1', 's'], ['2', '8']]