Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6619805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:01:04+00:00 2026-05-25T21:01:04+00:00

This javascript array contains coordinates that I send to Google Maps API to draw

  • 0

This javascript array contains coordinates that I send to Google Maps API to draw a path in the map. Sometimes coordinates[0] is empty because it depends on a previous route that might exist or not (using Google Maps).

This is my code:

coordinates = [];

(between here I look for a previous path (coordinates[0]). In this case we are asuming that it is null. So we have these values:

coordinates[1] = '50,20'; //route 1
coordinates[2] = '10,18'; //route 2
coordinates[3] = '27,34'; //route 3

After that, I draw the path in the map like this:

travel_path = new google.maps.Polyline({
  path: coordinates
});
travel_path.setMap(map);

The problem: When there is no coordinates[0] (that happens when there is no previous segment of the travel path) the .Polyline method throws an error because it needs to receive an array with sequenced indexes starting from 0.

The question: How can I convert my original array to this (compare indexes):

coordinates[0] = '50,20'; //route 1
coordinates[1] = '10,18'; //route 2
coordinates[2] = '27,34'; //route 3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:01:05+00:00Added an answer on May 25, 2026 at 9:01 pm

    coordinates.shift() removes the first element from the array.

    var coordinates = [];
    //coordinates[0] = undefined;
    coordinates[1] = '50,20'; //route 1
    coordinates[2] = '10,18'; //route 2
    coordinates[3] = '27,34'; //route 3
    coordinates.shift();
    

    coordinates.shift() causes this to happen:

    coordinates[0] = coordinates[1];
    coordinates[1] = coordinates[2];
    coordinates[2] = coordinates[3];
    //coordinates[3] is removed.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array in javascript. This array has strings that contains commas (,).
Possible Duplicate: Javascript - array.contains(obj) What's wrong with this: var zipCodes =(['90001','90002','90003']); Test if
I'd like to have an array in javascript that each item contains 2 properties
I have a global JavaScript array that contains some strings. I want to create
I have a numeric javascript array, that contains several objects with geodata in it.
1) I have this Javascript array: lang=new Array(); lang[sq]=Albanian; lang[ar]=Arabic; lang[en]=English; lang[ro]=Romanian; lang[ru]=Russian; 2)
I want to make a variable length array in Javascript. Is this possible. A
This javascript code does not work in IE8, but works in Firefox and Google
I have this Javascript data: [{id:123,type:test},{id:154,type:another}] How would you transform that into something so
I got this javascript code from off the internet. It's a script that changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.