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
- ref
- MUIbase
- JavaScript
- Sass
- CSS3
- ref전달하기
- gulp
- 자바스크립트
- MUISystem
- React
- next.js
- animation
- html
- tomcat
- Eclipse
- Study
- 이클립스
- 보일러플레이트
- error
- JOYUI
- SSR
- npm
- Adobe
- 1분코딩
- 정적웹사이트
- frontend
- TaskRunner
- css
- VW
- java
Archives
- Today
- Total
프론트 개발 블로그
구조 분해 할당 표현식 본문
구조 분해 할당 구문은 배열이나 객체의 속성을 해체하여 그 값을 개별 변수에 담을 수 있게 하는 표현식입니다.
- 구조 분해 할당 표현식
- spread 연산자
- rest 파라미터
비구조할당(구조분해 할당) 표현식
배열에서의 구조분해할당 표현식
|
1
2
3
4
5
6
|
// 기본 변수 할당
var foo = ['one', 'two', 'three'];
var [one, two, three] = foo;
console.log(one); // 'one'
console.log(two); // 'two'
console.log(three); // 'three'
|
|
선언에서 분리한 할당
|
1
2
3
4
5
|
var c, d;
[c, d] = [1, 2];
console.log(c); // 1
console.log(d); // 2
|
|
기본값 : 변수에 기본값을 할당하면 분해한 값이 undefiend일때 그 값을 대신 가져온다.
|
1
2
3
4
|
var e, f;
[e=1, f=2] = [30];
console.log(e); // 30
console.log(f); // 2
|
|
변수값 교환하기
|
1
2
3
4
5
|
var a = 1;
var b = 3;
[a, b] = [b, a];
console.log(a); // 3
console.log(b); // 1
|
|
함수가 반환한 배열 분석
|
1
2
3
4
5
6
7
8
9
|
function f() {
return [1, 2];
};
var a, b;
[a, b] = f();
console.log(a); // 1
console.log(b); // 2
|
|
Spread 연산자
배열을 분해
반응형
'Javascript' 카테고리의 다른 글
| 비동기처리 (0) | 2020.03.02 |
|---|---|
| scope / hoisting (0) | 2020.02.24 |
| [JS문법] 조건문 사용하기 (0) | 2020.02.20 |
| Array.prototype.join() (0) | 2020.02.19 |
| Array.prototype.sort() (0) | 2020.02.19 |