I want to find out all of my values, and then sum, But how to separate the values and keys How to write agghh agghh
CodePudding user response:
The function sum (k) { Var kk=0; For (let n in k) Kk +=k [n]. Return kk. } Var obj={ A: 54.7. B: 99.8. C: 35.5 }; The console. The log (sum (obj));
CodePudding user response:
CodePudding user response:
Use 1/f,
The function sum (k) { The return Object. Values (k). Reduce ((sum, value)=& gt; { Return the sum +=value; }, 0) } Var obj={ A: 54.7. B: 99.8. C: 35.5 }; The console. The log (sum (obj));