0

I got geo-coordinates from an API. An try to log them to the console separately. When I log them as an array everything works, but when I try to access the elements in it with array[0] the console says undefined... What am I doing wrong? Here is the code:

  async function get_geocode(x) {
  const response = await fetch(x);
  
  const data = await response.json();
  console.log(data.features[0].center,"center");
  let lo = data.features[0].center[0];
  let la = data.features[0].center[1];
  lo = parseFloat(lo);
  la = parseFloat(la);
  console.log(lo, la, "lola");
  return [lo, la];
}


document.getElementById("mybutton").onclick = function(){
  //let coordinates=[];
  //var coordinates = new Float32Array(2);
  let values = [];
  [...]

  
  values = get_geocode(geocode_api_link);
  console.log(values, "coordinates");
  console.log(values[0], "eins");
  console.log(values[1], "zwei");



}

And the output is:

[Log] (2) (index.js, line 36) Promise

result: [12.345678, 99.345678] (2)

status: "resolved"

Promise Prototyp "coordinates" [Log] undefined – "eins" (index.js, line 37)

[Log] undefined – "zwei" (index.js, line 38)

[Log] (2) (index.js, line 5) [12.345678, 52.456213] (2) "center"

[Log] 12.345678 – 99.345678 – "lola" (index.js, line 10)

So I can log the whole array but not the single elements in it.. What do I do wrong?

zksparks
  • 1
  • 1

0 Answers0