const prices = [10.99, 5.99, 3.99, 6.59]

 

prices.foreach((price, idx) => {

        const priceObj = {index : idx, taxAdjustedprices : price *(1 + tax)}

        taxAdjustedprices.push( priceObj 

})

 

 

price  : 는 배열의 값을 나타낸다

idx는 배열의 순서를 나타낸다

 

 

const sum = prices.reduce((prevValue, curValue) => {

     return prevValue + curValue;

},0);

 

prevValue : 초깃값 (,0이기 때문에 초깃값이 0이다 ,1이라면 초깃값은 1)

curValue : 다음 배열값(0번째 배열의 값을 처음에 prevValue와 더한다)

return을 해서 배열이 끝날때까지 계속 반환한다.

'개인 공부 -자바스크립트' 카테고리의 다른 글

EVENT  (0) 2023.10.16
자바스크립트(객체)  (0) 2023.10.12
자바스크립트 오류(Access to script at ~)  (1) 2023.10.06

+ Recent posts