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.

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.