Tell me whether there is a more competent solution for the addition of array values
Now I do this
count = [];
Array.Foreach (Data, Index) {
Count [index] = data.number;
});
Eval (Count.Join ('+'));
displays the amount (here all the rules), but since I am new to JS, maybe there is a more competent and more correct decision, and not glue everything through Eval.
tried different options, but something I could not achieve a positive effect.
Answer 1, Authority 100%
var count = 0;
Array.Foreach (FUNCTION (VALUE, INDEX) {
Count + = + Value;
});
Answer 2, Authority 400%
Use reduce :
var sum = array.Reduce (FUNCTION (PREVIOUSVALUE, VALUE) {
RETURN PREVIOUSVALUE + VALUE;
});