Pulling data from an esriRequest

642
1
Jump to solution
07-25-2018 07:14 AM
JustinBridwell2
Occasional Contributor II

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?

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You just have to use

console.log(resp[1]);

View solution in original post

1 Reply
KenBuja
MVP Esteemed Contributor

You just have to use

console.log(resp[1]);