티스토리 뷰
5.9 Object.keys, values, entries
위 함수들의 결과값은 실제 배열로 반환된다.
Transforming objects
Objects는 배열로써 처리하는 함수들이 존재하지 않아서, 관련처리를 하고 싶으면 아래와 같이 해야한다. (잘 이해되진 않는다...)
let prices = {
banana: 1,
orange: 2,
meat: 4,
};
let doublePrices = Object.fromEntries(
// convert prices to array, map each key/value pair into another pair
// and then fromEntries gives back the object
Object.entries(prices).map(entry => [entry[0], entry[1] * 2])
);
alert(doublePrices.meat); // 8
'스터디 > JavaScript' 카테고리의 다른 글
모던 자바스크립트 튜토리얼 part1 - 5.11 (0) | 2024.05.21 |
---|---|
모던 자바스크립트 튜토리얼 part1 - 5.10 (0) | 2024.05.21 |
모던 자바스크립트 튜토리얼 part1 - 5.7 ~ 8 (0) | 2024.05.21 |
모던 자바스크립트 튜토리얼 part1 - 5.6 (0) | 2024.05.20 |
모던 자바스크립트 튜토리얼 part1 - 5.5 (0) | 2024.05.20 |
댓글