ES6
Array.of() 및 Array.from()
으누아빠
2021. 3. 31. 14:31
반응형
Array.of()
Array.of() 메서드는 인자의 수나 유형에 관계없이 가변 인자를 갖는 새 Array 생성
const items = Array.of("a", "b", "c");
console.log(items); // (3) ["a", "b", "c"]
Array.from()
Array.from() 메서드는 유사 배열 객체(array-like object)나반복 가능한 객체(iterable object)를 이용해
새 Array 생성
const m = new Map([[1, 2], [2, 4], [4, 8]]);
Array.from(m);
// [[1, 2], [2, 4], [4, 8]]
const mapper = new Map([['1', 'a'], ['2', 'b']]);
Array.from(mapper.values());
// ['a', 'b'];
Array.from(mapper.keys());
// ['1', '2'];