jblayney
asked on
combine total value of array
hello,
I have this code:
How do i console.log the toal value of daysOfWeek?
I have this code:
let daysOfWeek = {
"Mon": 5,
"Tues": 2,
"Friday": 3
}
How do i console.log the toal value of daysOfWeek?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The modern way is to reduce
https://jsfiddle.net/mplungjan/enjwbo5h/
Note: The for..in is more descriptive if you use day
PS: JAVA is not JavaScript
https://jsfiddle.net/mplungjan/enjwbo5h/
const total = Object.values(daysOfWeek).reduce((a,b) => a+b)
Note: The for..in is more descriptive if you use day
let total = 0;
for (let day in daysOfWeek) {
total += daysOfWeek[day];
}
PS: JAVA is not JavaScript
Excellent answer Michel.
Thanks, Daniel
ASKER