Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
Tags
- ChatGPT
- nodeJS
- javascript
- stream
- Functional Programming
- 함수형프로그래밍
- MSA
- Generics
- Linux
- ES6
- 비주얼 스튜디오 코드
- nestjs
- 알고리즘
- node.js
- MSK
- Let's Encrypt
- html
- 파이썬
- typescript
- docker
- Certbot
- Express
- NPM
- https
- V8
- GIT
- Schema Registry
- 자료구조
- python
- vscode
Archives
- Today
- Total
JangBaGeum.gif
[JavaScript] Convert ES6 Iterable to Array 본문
Set()
- Array.from과 spread syntax인 ...을 사용 가능하다.
const x = new Set([ 1, 2, 3, 4 ]);
const y = Array.from(x);
console.log(y); // = [ 1, 2, 3, 4 ]
const z = [ ...x ];
console.log(z); // = [ 1, 2, 3, 4 ]
Met()
- map도 Array.from과 spread syntax(...)의 사용이 가능하다.
const map = new Map([[ 1, 'one' ],[ 2, 'two' ]]);
const newArr1 = [ ...map ];
const newArr2 = Array.from( map );
console.log(newArr1); // [[ 1, 'one' ],[ 2, 'two' ]]
console.log(newArr2); // [[ 1, 'one' ],[ 2, 'two' ]]
- Array.from, spread syntax(...)와 함께 map.values() 혹은 map.keys()를 사용한다면 key 혹은 value만 추출한 iterable object를 추출 가능하다.
const map = new Map([[ '1', 'one' ],[ '2', 'two' ]]);
const newArrKeys = [ ...map.keys() ];
const newArrValues = [ ...map.values() ];
console.log(newArrayKeys) // ['1', '2']
console.log(newArrayValues) // ['one', 'two']
'ETC > 알고리즘 & 문법' 카테고리의 다른 글
[JavaScript]Date Object에서 Year/Month/Date 얻기 (1) | 2022.11.17 |
---|---|
[JavaScript] ES6 Map() (0) | 2022.11.16 |
[FP] 순수 함수와 비 순수 함수 (0) | 2022.10.11 |
[TypeScript] Generics (0) | 2022.07.13 |
[JavaScript] Computed Property Name (0) | 2022.07.12 |