I am trying to use a value from inside one getJSON
, forEach
method in another. Is there any way for me to do that?
JavaScript
By the comment you wrote, I'd prefer do it like this (think that both will have same length):
var first, second;
$.when(
$.getJSON(json1, result => first = result),
$.getJSON(json2, result => second = result)
).then(function() {
if (first && second) {
let results = first.map((item, index) => item.x / second[index].v);
// do whatever you want
}
});