Home > front end >  Js Object to how peace!!!!!
Js Object to how peace!!!!!

Time:09-26

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));

CodePudding user response:

Var a variable, and save time

CodePudding user response:

reference 1/f, the sky wave 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));
for n in k (let) me feel should find k, because this is a STR, I have to find the value, so I feel I want to use the Object. The values ()

CodePudding user response:

The
references 4 floor huangfuyk. Response:
var a variable, save time and
I know, but I just can't, what value to find out

CodePudding user response:

The
refer to the third floor and foliage quiet reply:
borrow 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));
the reduce () this function is why ah
  • Related