0
$.getJSON("http://localhost:8080/geoserver/Tourism/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Tourism:geot_alldata_utm1&maxFeatures=5000&outputFormat=application%2Fjson", function(result){
    var i;
    for(i = 0; i < 200; i++){
        var img = (result["features"][i]["properties"]["image"]);
        var temp =(result["features"][i]["properties"]["class"]);
        type.push(temp);
        images.push(img);
    }
});

console.log(type[0]);

I have written above code to store specific value from JSON object into two global arrays that i have declared. But i am not able to access the variables by index added to the array.

  • 1
    JSON object? There's no [JSON object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) involved in your question ... Maybe there should? – Teemu Jul 06 '17 at 09:11
  • You cannot use same name for both local and global arrays in the same time. – malisit Jul 06 '17 at 09:11
  • @Teemu he is pushing to a global array inside an async function and is wondering why `console.log(type[0])` is undefined outside of the callback. That's exactly what the dupe answers. – baao Jul 06 '17 at 09:16
  • 1
    @baao Yeah, I realized that, unfortunately too late. I've removed the comment already. – Teemu Jul 06 '17 at 09:17

0 Answers0