javascript - Multidimensional array push -


how can this?

"type" = string

showmarkers('vehicles'); showmarkers('houses');  hidemarkers('vehicles');  var my_array = []; function showmarkers(type) {     //code     var gmm = new google.maps.marker(     {         //code     });     my_array[type].push(gmm);     //uncaught typeerror: cannot call method 'push' of undefined  }  function hidemarkers(type) {     for(var = 0; < my_array[type].length; i++)     {         my_array[type][i].setmap(null); //hide markers     }     my_array[type] = []; //empty array of `type` } 

i got 3 different map icons want users able remove individually

th problem my_array[type] undefined if call showmarkers before hidemarkers.

change function this:

function showmarkers(type) {     //code     var gmm = new google.maps.marker(     {         //code     });     if (!(my_array[type] instanceof array)) {         my_array[type] = [];     }     my_array[type].push(gmm); } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -