AnsweredAssumed Answered

Pulling data from an esriRequest

Question asked by jbridwell_Dewberry on Jul 25, 2018
Latest reply on Jul 25, 2018 by kenbuja

Hey All,

      I am using an esri/request call to get data back from an api. Now I'm trying to pick out individual pieces of that data and push them to an empty array that I can further manipulate. Here is how I have the esriRequest code setup. Notice I have a little function called `showResults` to use instead of console.info(resp). I wanted to use this to try and dissect the data be returned in the response (resp):

esriRequest({
    url:"https://api.census.gov/data/2016/acs/acs5",
    content:{
        get: 'NAME,B01003_001E,B02001_001E,B06007_001E,B06010_001E',
        for: `tract:${ACS_TRCT}`,
        in: [`state:${ACS_ST}`,`county:${ACS_CNTY}`]
    },
    handleAs:'json',
    timeout:15000
    }).then(function(resp){
        console.info(resp);
    // showResults(resp);
    }, function(error){
        alert("Data failed" + error.message);
    });
    function showResults(resp) {

        console.log(resp.data);
    };
....

Basically, the call returns an object with 2 arrays; 1 that is basically labels and 2 the actual data I want. Essentially I am trying to pick out the data from array 2 ( or array[1], if you will), index 1-4.

When I try to use my showResults function that uses console.log(resp.data); , it just returns `undefined`. What am I doing wrong here and how do pick out the array[1] data?

Outcomes