let arr = [];
navigator.geolocation.getCurrentPosition(
function(position) { // success cb
console.log(position);
arr.push(position.coords.longitude);
arr.unshift(position.coords.latitude);
},
function() {
return " ";
});
console.log(arr); //logs the output just fine
let x = arr[0]; //gives undefined
let y = arr[1]; //gives undefined
Anytime I try to access the arr
array, it gives me undefined. I want x
to be equal to the longitude co-ordinate and y
to the latitude co-ordinate.