ES6

KoEunseo·2022년 7월 12일
0

javascript

목록 보기
8/32

spread/rest

spread

전개 구문

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Spread_syntax
배열을 풀어서 인자로 전달하거나 각각의 요소로 넣을 때 사용
배열을 펼친다
immutable

sum(...numbers);
[interableObj, '4', 'five', 6];
let objClone = {...obj};
  • 배열에서 사용
    배열 합치기, 복사(=arr.slice())
  • 객체에서 사용

rest

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Functions/rest_parameters

나머지 파라미터
파라미터를 배열의 형태로 받아서 사용. 파라미터 개수가 가변적일때
남아있는 모든 인자를 하나의 배열에 담는다.

Destructuring

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

구조분해할당
spread문법을 이용해 값을 해체한 후 개별 값을 변수에 새로 할당
선언과 함께 사용해야 함


const [a, b, ...rest] = [ 1, 2, 3, 4, 5]
// a = 1, b = 2, rest = [3, 4, 5]
const {a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40}
// a = 10, b = 20, rest = {c: 30, d: 40}
profile
주니어 플러터 개발자의 고군분투기

0개의 댓글