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

  • SEARCH
  • Home
  • 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 189231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:09:19+00:00 2026-05-11T16:09:19+00:00

In my Google Maps application I can place markers on the map, and I

  • 0

In my Google Maps application I can place markers on the map, and I keep a reference to each of the markers placed, along with some extra information in an array called markers.

Adding markers is easy, I just push() the newly created object onto the array (markers.push(marker));

However, when it comes to removing an arbitrary marker from the array, given an index of the slot, it doesn’t behave as expected. My function is:

function deleteMarker(markerIndex) {
    if (markerIndex!='' && markerIndex>=0 && markerIndex<markers.length) {
        if (confirm('Do you really want to remove this marker from the map?')) {
            alert('deleting marker '+markerIndex); //debugging purposes
            markers.splice (markerIndex, 1);
        }
    }
}

I have no previous experience with the splice() function, but looking at its description @ w3schools it seems to be pretty straight-forward. However, I get the following behaviour:

markers.splice() does nothing. So what am I doing wrong?

And also, when markerIndex is 0 no confirmation box is shown. At first I assumed the lengthy if-condition evaluated to false and so the whole code block was skipped, however, using Firebug to step through the calls I found out that the condition holds (of course) for index 0 when array is non-empty, next step reveals that the if (confirm(...)) and alert('deleting...) are skipped and markers.splice() is called (but nothing happens). This behaviour is so strange I decided to open this question.

Can anyone please clarify what’s going on?

I thought that deleting markers will be the easiest bit of functionality one could do. I can add them, edit their contents, even clear all markers (pop()-ing markers off the markers array until empty) and all works nicely.

  • 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-11T16:09:19+00:00Added an answer on May 11, 2026 at 4:09 pm

    One problem with your code is that JavaScript interprets 0 == '' as true, so for a markerIndex of zero, your confirm-code is not executed. I guess that you misinterpreted the steps Firebug shows or that it simply is buggy here since your if-condition will in fact evaluate to false for a markerIndex of 0.

    You can use type-strict comparison by adding an extra =:

    if (markerIndex !== '' && ...) {
    

    An easier approach would be:

    if (markers[markerIndex] !== undefined) {
    

    Since JavaScript does not raise an error when accessing undefined object members.

    Your other problem with splice() not working is weird (it should work).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Google maps in some region can serve traffic information showing the blocked roads and
I want to know if i can create a custom google maps application,on which
After I downloaded the Google Mail and Google Maps application into my mobile phone
I am having some trouble with the Google Maps API . I have an
I have loaded google map application in iphone . I am using UIWebView Control
I noticed that Google maps is providing directions in my local language (hungarian) when
My site uses the Google Maps API . In situations where the connection to
We recently discovered that the Google Maps API does not play nicely with SSL.
I have a page with a Google Maps mashup that has pushpins that are
I'm currently working on a Google Maps project and am implementing a search function.

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.