Title: JS array problem
Last modified: August 19, 2016

---

# JS array problem

 *  [masterix](https://wordpress.org/support/users/masterix/)
 * (@masterix)
 * [18 years ago](https://wordpress.org/support/topic/js-array-problem/)
 * Hi,
 * I’m writing plugin with Google Maps and I have a code:
 *     ```
       function show_all( id )
       {
         var url = '../wp-content/plugins/GoogleMaps/xml_gen.php?id='+id;
         var markers_arr = [];
         GDownloadUrl( url, function( data, response )
         {
           var xml = GXml.parse( data );
           var markers = xml.documentElement.getElementsByTagName( "marker" );
           map.setCenter( new GLatLng( parseFloat( markers[0].getAttribute( "lat" ) ), parseFloat( markers[0].getAttribute( "lng" ) ) ), 12 );
           for( var i = 0; i < markers.length; i++ )
           {
             var point = new GLatLng( parseFloat( markers[i].getAttribute( "lat" ) ), parseFloat( markers[i].getAttribute( "lng" ) ) );
             var marker = new GMarker( point );
             markers_arr[i] = marker;
             marker.txt = markers[i].getAttribute( "etiq" );
             map.addOverlay( marker );
           }
         } );
        for( var j = 0; j < markers_arr.length; j++ )
        {
                alert( markers_arr[j].getPoint() );
                document.getElementById( "status" ).innerHTML += markers_arr[j].getPoint()+" ";
        }
       }
       ```
   
 * It is in admin.js file and is used only by Administrator pages. The problem is
   with arrays because I can’t see any alert after invoking this function. What’s
   wrong with it? When I have i simple HTML page it works. I include JS code in 
   this way:
 * `add_action( 'admin_print_scripts', array( &$gm, 'JSAdminOutput' ) );`
 * And method JSAdminOutput looks like this:
 *     ```
       public function JSAdminOutput()
           {
             echo "<script type='text/javascript' src='".get_option( 'siteurl' )."/wp-content/plugins/GoogleMaps/js/admin.js'></script>";
             echo "<script src='http://maps.google.com/maps?file=api&v=2&key=".($this->api_key)."' type='text/javascript'></script> ";
           }
       ```
   
 * Thanks for any responses and tips 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [marcinpl87](https://wordpress.org/support/users/marcinpl87/)
 * (@marcinpl87)
 * [18 years ago](https://wordpress.org/support/topic/js-array-problem/#post-774321)
 * I have the same problem like [@masterix](https://wordpress.org/support/users/masterix/)
   
   Anymore suggestions? :/
 *  Thread Starter [masterix](https://wordpress.org/support/users/masterix/)
 * (@masterix)
 * [18 years ago](https://wordpress.org/support/topic/js-array-problem/#post-774324)
 * Problem is solved. It was about asynchronous communication via GDownloadUrl(),
   for loop was executed before all data was retrievec by GDownloadUrl() function.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘JS array problem’ is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [masterix](https://wordpress.org/support/users/masterix/)
 * Last activity: [18 years ago](https://wordpress.org/support/topic/js-array-problem/#post-774324)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
