Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 여행
- 해외여행
- ES6
- autocomplate
- 마사지
- 맛사지
- REACT
- webpack.config.js
- 네이버페이사기
- JavaScript
- 구분
- plugin
- 정직하게사세요
- Webpack
- 특수문자
- 사기
- 세부
- Hooks
- 스노쿨링
- 유효성검사
- 중고나라사기
- 중고나라
- 삼성무선청소기제트
- 자동완성
- 정규식
- 중고거래사기
- js
- 막탄
- 스쿠버다이빙
Archives
- Today
- Total
Ryu.log
Array.from() 본문
Array.from()
Array.from()
메소드는 배열로 변환할 유사 배열 혹은 반복 가능한 객체를 이용하여, 복사된 배열을 리턴 해준다.
console.log(Array.from('foo')); // expected output: Array ["f", "o", "o"]
console.log(Array.from([1, 2, 3], x => x + x)); // expected output: Array [2, 4, 6]
Array.from(Array, MapFn(thisArg));
// Array : 배열로 변환할 유사배열 또는 반복가능한 객체
// MapFn : 모든 배열요소에서 호출할 Map 함수
// thisArg : Map함수 내에 item으로 사용될 값
예제 코드
String에서 배열만들기
Array.from('foo'); // ["f", "o", "o"]
Set에서 배열만들기
const s = new Set(['foo', window]); Array.from(s); // ["foo", window]
Map에서 배열만들기
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'];
배열형태를 가진 객체(arguments)에서 배열만들기
function f() { return Array.from(arguments); } f(1, 2, 3); // [1, 2, 3]
Array.from과 Arrow함수 사용하기
Array.from([1, 2, 3], x => x + x); // [2, 4, 6]
Array.from(, (v, i) => i); // [0, 1, 2, 3, 4]
'Prev-content' 카테고리의 다른 글
string.localeCompare() (0) | 2018.11.12 |
---|---|
String.prototype.repeat() (0) | 2018.11.09 |
[ Redux 유용 ] 리액트 App에 손쉽게 store를 연결시켜주는 Provider 컴포넌트 (0) | 2018.09.20 |
[ React + redux 05 ] 애플리케이션 상태관리 - 스토어 생성 (0) | 2018.09.20 |
[ React + redux 04 ] 애플리케이션 상태관리 - 리듀서 생성 (0) | 2018.09.20 |
Comments