1
var jData = JSON.stringify(data)
 
 $.each(jData,function(key, value) {
 var usedAccu += jData[9][value];
 });

jData is Json array in the format like [{"key1": value, "key2": value, ... }, {..}].
I want to loop thru the array and keep adding key10's value into the variable called usedAccu.

asked Apr 17, 2021 at 5:43

1 Answer 1

1

You can try like below :

var usedAccu = 0
var jData = [{
 "key1": "1",
 "key2": "5",
}, {
 "key1": "1",
 "key2": "22",
}]
$.each(jData, function(key, value) {
 usedAccu += parseInt(value.key2) //change to your required keyname
});
console.log(usedAccu)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

answered Apr 17, 2021 at 5:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.