0

I am having trouble outputting values from an array when I have pushed them through multiple ajax async calls.

I can output the main array in a console log but printing out the individual values I cannot. I also would like to sort the values high to low

$(document).ready(function() {
  var callsArray = [];

  $.ajax({
    type: 'GET',
    url: "js/equity-one.json",
    dataType: "json",
    traditional: true,
    async: true,
    success: function(data) {
      $.each(data, function(i, item) {
        callsArray.push(item);
        $(".equity").append("<tr><td>" + item + "</td></tr>");
      });
    }
  });

  $.ajax({
    type: 'GET',
    url: "js/equity-two.json",
    dataType: "json",
    traditional: true,
    async: true,
    success: function(data) {
      $.each(data, function(i, item) {
        callsArray.push(item);
        $(".equity").append("<tr><td>" + item + "</td></tr>");
      });
    }
  });

  $.ajax({
    type: 'GET',
    url: "js/equity-three.json",
    dataType: "json",
    traditional: true,
    async: true,
    success: function(data) {
      $.each(data, function(i, item) {
        callsArray.push(item);
        $(".equity").append("<tr><td>" + item + "</td></tr>");
      });
    }
  });
  console.log(callsArray); // This outputs what has been pushed
  var arr = callsArray.sort();
  for (let x = 0; x < arr.length; x++) { //Not sure what to do here

    console.log(arr[x]);
  }

});

JSON Example

{"equity" : 5000} //File 1
{"equity" : 2000} //File 2
{"equity" : 10000} //File 3
roshambo
  • 2,624
  • 6
  • 31
  • 54

0 Answers0