(#6) How to add numbers in an array On ReactJs?

const cart = useSelector(state => state.cart) //from Redux stateconst {cartItems} = cart //cartItems=[3, 2, 1, 2]; const totalqty=cartItems.map(qty =>qty.qty)
// You can use either way of reduce method

const qtysum = totalqty.reduce(function(total, current) {
return total + current;}, 0);orconst qtysum = totalqty.reduce((total, current)=> total + current,0);//qtysum = 8