concat() 메서드는 인자로 주어진 배열이나 값들을 기존 배열에 합쳐서 새 배열을 반환합니다.
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3)
// expected output: Array ["a", "b", "c", "d", "e", "f"]
배열.reduce((누적값, 현재값, 인덱스, 요소) => {
return 결과
}, 초기값)
reduce() 메서드는 배열의 각 요소에 대해 주어진 리듀서(reducer) 함수를 실행하고, 하나의 결과값을 반환합니다.
const array1 = [1, 2, 3, 4];
// 0 + 1 + 2 + 3 + 4
const initialValue = 0;
const sumWithInitial = array1.reduce(
(previousValue, currentValue) => previousValue + currentValue,
initialValue
);
console.log(sumWithInitial);
// expected output: 10
if(pickedCards.length > 2) {
const names = pickedCards.reduce((acc, cur) => {
return acc = acc.concat(`${cur.name}, `)
}, "")
return alert(`당첨자는 ${names} 입니다.`)
}