[JavaScript]'...' three dot 함수, 'array[i] || []' 함수
5901 단어 JavaScriptJavaScript
'...' three dot 함수
'array[i] || []' 함수
'...' three dot 함수
- Rest Parameter
배열이기 때문에 arguments 객체를 배열로 변환할 필요없이 바로 argument의 배열에 JavaScript의 Array instance method를 적용할 수 있다는 점에서 유용하게 쓰일 수 있습니다.
function sumWithRest(... args) {
for(let i = 0 ; i < args.length; ++i) console.log(args[i]);
return args.reduce((acc, cur) => acc + cur);
}
sumWithRest(1, 2, 3, 4);
- Destructuring rest parameters
함수 안에서 argument들의 배열을 array destructuring 한 효과를 얻을 수 있습니다.
function destructuringParam(... [a, b, c]) {
console.log(a, b, c);
}
destructuringParam(1, 2, 3);
- Spread Operator
let ar = ['hello', 'nello'];
let ar2 = ['dello', 'bello']
console.log(ar);
console.log(...ar);
console.log([...ar, ...ar2]);
//[ 'hello', 'nello' ]
//hello nello
//[ 'hello', 'nello', 'dello', 'bello' ]
'array[i] || []' 함수
x에 값이 있으면 x에 할당하거나 빈 배열 []로 초기화합니다.
var x = x || [];
Author And Source
이 문제에 관하여([JavaScript]'...' three dot 함수, 'array[i] || []' 함수), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@rssungjae/JavaScript...-three-dot-함수-arrayi-함수저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)