javascript
spread operator ( 스프레드 연산자 )
hello-world
2021. 1. 19. 23:04
728x90
반응형
스프레드 연산자
- 요소 끼리 합치기 / 새로운 배열 생성 등 정말 유용하게 많이 쓰인다.
//
var a, b, c, d, e;
a = [1,2,3];
b = "dog";
c = [42, "cat"];
// Using the concat method.
d = a.concat(b, c);
// Using the spread operator.
e = [...a, b, ...c];
console.log(d);
console.log(e);
// Output:
// 1, 2, 3, "dog", 42, "cat"
// 1, 2, 3, "dog", 42, "cat"
//
참고 - MS - https://msdn.microsoft.com/ko-kr/library/dn919259(v=vs.94).aspx
MDN - https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Spread_operator
전개 구문 - JavaScript | MDN
전개 구문을 사용하면 배열이나 문자열과 같이 반복 가능한 문자를 0개 이상의 인수 (함수로 호출할 경우) 또는 요소 (배열 리터럴의 경우)로 확장하여, 0개 이상의 키-값의 쌍으로 객체로 확장시
developer.mozilla.org
반응형