I had the following json
var data = {
"total": "",
"scores": [{
"subject": "maths",
"marks": "50"
}, {
"subject": "science",
"marks": "75"
}]
};
Now in the total ,value should be 125 which should be updated automatically. Also in the scores keys ,the values will be coming dynamically.So all the marks should be added automatically and displayed in total. So how can I do this with any javascript . Can someone help me. Thanks!
Expected
var data = {
"total": "125",
"scores": [{
"subject": "maths",
"marks": "50"
}, {
"subject": "science",
"marks": "75"
}]
};
iteration. Iterate your array of objects and calculate