holdanddeepdive/javascript-deep-dive

27장 배열

Opened this issue · 0 comments

[몰랐던 부분]

Array.of

전달된 인수를 요소로 같는 배열을 생성

Array.of(1, 2, 3) //[1, 2, 3]

Array.from

유사배열 객체 또는 이터러블 객체를 배열로 변환

Array.from({ length: 2, 0: 'a', 1: 'b' }) // ['a', 'b']

Array.prototype.unshift

const arr = [1, 2];
arr.unshift(3, 4)
arr; // [1, 2, 3, 4]

Array.prototype.shift

const arr = [1, 2];
arr.shift()
arr; // [1]

Array.prototype.flatMap

const arr = ['hello', 'world'];

arr.map(x => x.split('')).flat(); // ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']
arr.flatMap(x => x.split('')); // ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']