Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Local variable push to global array in Javascript

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!