Answer the question
In order to leave comments, you need to log in
How to add numbers from "base" JSON?
Hello!
I have a small JSON array like this:
[
{
"id": 0,
"price": "100"
},
{
"id": 1,
"price": "50.95"
}
]
Answer the question
In order to leave comments, you need to log in
var test = '[{"id": 0,"price": 100},{"id": 1,"price": 50.95}]',
sum = 0;
test = JSON.parse(test);
for (var i = 0; i < test.length; i++) {
sum += test[i].price;
}
alert(sum);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question