개발자/그냥 js
spread syntax vs rest syntax
YoungDogg
2022. 1. 12. 14:38
Spread
- 요소들을 '흩뿌리는' 개념이다. 파라미터에서 쓰며 배열 또는 객체를 '뿌리는데' 쓴다.
- 두 개 이상의 배열이나 객체를 하나로 합치는데 쓴다.
Rest
- 요소들을 '모으는' 개념이다.
- 객체를 지우는 데 쓰기도 한다.
Rest를 이용하면 객체의 값을 삭제할 수 있다. delete를 사용 할 수도 있지만 현업에선 기존 값을 잘 삭제하지 않는다.
참고 사이트
Javascript Spread and Rest Syntax (...) | Better Programming
Spread Syntax (…) vs. Rest Syntax (…) in JavaScript
Understand the difference with two examples of each
betterprogramming.pub
javascript - Spread Syntax ES6 - Stack Overflow
Spread Syntax ES6
Consider the following sample code var x = ["a", "b", "c"]; var z = ["p", "q"]; var d = [...x, ...z]; var e = x.concat(z); Here, the value of d and e are exactly same and is equal to ["a", "b"...
stackoverflow.com