reduce함수를 이용한 전체 합 구하기
let numbers = [1,2,3,4,5] let total = numbers.reduce(function(acc,cur){ return acc + cur }); console.log(total);//15 let total = [{qunt: 1}, {qunt: 2}, {qunt: 1}].reduce( (acc, cur) => acc + cur.quntity , 0 ) console.log(total) // 결과값: 4 let max = [1, 2, 3, 4, 5].reduce( ( max, cur ) => Math.max( max, cur ) ); console.log(max) // 결과값: 5 reduce 함수는 네개의 인수를 사용한다. Accumulator(누적값) Current Value(배열의..
04 array.map()
let numbers = [1,2,3,4,5]; let newNumbers = numbers.map(n=>n*2); console.log(newNumbers); //2,4,6,8,10 map 메서드로 출력하기 arr.map(callback(currentValue[, index[, array]])[, thisArg]) developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/map