조정밍
JM IT BLOG
조정밍
전체 방문자
오늘
어제
  • 분류 전체보기 (37)
    • Web (8)
      • Server (4)
      • Spring (2)
    • JavaScript (6)
    • Database (1)
    • Java (5)
    • Cryptography (8)
    • Network (1)
    • Reverse (2)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 블록암호
  • JSONParser
  • RSA 암호화
  • ln -s
  • dll
  • Gradle
  • 빌터패턴
  • react
  • Dynamic Library Link
  • Base64 #인코딩
  • JSX
  • 대칭키암호
  • RSA 알고리즘 구현
  • ln 명령어
  • nullish
  • 정적라이브러리
  • Gson
  • 공개키 암호 알고리즘
  • @Builder
  • 빌드도구

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
조정밍

JM IT BLOG

[Javascript] 전개구문(spread syntax)
JavaScript

[Javascript] 전개구문(spread syntax)

2021. 9. 5. 19:57

Spread Syntax?

ECMAScript6(2015) 에서 새로 추가된 문법이다.

spread operator는 반복 가능한(iterable) 객체에 적용할 수 있는 문법이다.

배열이나 문자열 등을 풀어서 요소 하나 하나로 전개 시킬 수 있다. 

함수 호출

매개변수에 전개구문을 사용할 수 있다.

 

구문

exFunction(...iterableObj);

예시

function add(x, y) {
	return x + y;
}

const arr = [1, 2];

console.log(add(...arr)); //3

 

 

배열 리터럴과 문자열

구문

[...iterableObj, '1', 2];

예시

const arr = [1, 2];

console.log(...arr); //[1, 2]
const arr1 = [1, 2, 3];
const arr2 = [4, 5];
const arr3 = [...arr1, ...arr2];

console.log(arr3); //[1, 2, 3, 4, 5]

 

객체리터럴

ECMAScript(2018)에서 추가됨

 

구문

exFunction(...iterableObj);

예시

const obj1 = {
    a : '1',
    b : '2'
}

const obj2 = {
    ...obj1,
    c : '3'
};

console.log(obj1);
console.log(obj2);

 

 

Reference

- https://bigtop.tistory.com/62

- https://chanhuiseok.github.io/posts/js-8/

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

'JavaScript' 카테고리의 다른 글

[javascript] 화살표 함수(Arrow Function)  (0) 2021.09.24
[javascript] 템플릿 리터럴 (Template Literal)  (0) 2021.09.23
[javascript] Optional Chaining '?.'  (0) 2021.09.23
[Javascript] 구조 분해 할당 (Object destructuring)  (0) 2021.08.05
[Javascript] Nullish coalescing ("??")  (0) 2021.08.04
    'JavaScript' 카테고리의 다른 글
    • [javascript] 템플릿 리터럴 (Template Literal)
    • [javascript] Optional Chaining '?.'
    • [Javascript] 구조 분해 할당 (Object destructuring)
    • [Javascript] Nullish coalescing ("??")
    조정밍
    조정밍

    티스토리툴바