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 | 31 |
Tags
- node.js란
- node.js
- 성장기
- ServerSentEvent
- 실시간알림
- Partition
- mariadb
- SSE
- localStorage
- PostgreSQL
- partitioning
- 파티셔닝
- Lag
- 열공하자
- 개발자
- frontend
- Node.js기본
- EventSource
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[JS Level up][Ch1][데이터] 전개 연산자 본문
전개 연산자(Spread)
배열의 아이템을 쉼표(,)로 구분하여 전개해서 출력
전개 연산자 기호 : ...
const fruits = ['Apple', 'Banana', 'Cherry'];
console.log(fruits);
console.log(...fruits); // 전개 연산자
function toObject(a, b, c) { // ...c를 사용하면 나머지 모든 인수를 받아낼 수 있다.
return {
a : a, // 속성의 이름과 변수의 이름이 같으면 축약형으로 사용할 수 있다. -> a,
b,
c
}
}
// toObject 함수가 같은 기능을 하는 함수(화살표 함수를 이용해 축약)
const toObj = (a, b, c) => ({a, b, c});
// Apple -> a, Banana -> b, Cherry -> c 인수로 들어옴
console.log(toObject(...fruits));
// 상단 코드와 같은 결과를 출력하지만 데이터가 많으면 매우 불편함
console.log(toObject(fruits[0], fruits[1], fruits[2]));
console.log(toObj(...fruits));
'파도파도 나오는 JavaScript' 카테고리의 다른 글
[JS Level up][Ch1][데이터] 얕은 복사와 깊은 복사 (0) | 2022.01.31 |
---|---|
[JS Level up][Ch1][데이터] 불변성 (0) | 2022.01.31 |
[JS Level up][Ch1][데이터] 구조 분해 할당 (0) | 2022.01.31 |
[JS Level up][Ch1][데이터] 객체 (0) | 2022.01.29 |
[JS Level up][Ch1][데이터] 배열-2 (0) | 2022.01.29 |
Comments