tags:

views:

165

answers:

3

Hi, this is a simple question. In PHP, when you want to know what's inside an array, you say :

print_r ($array);

But how do you do it in Javascript?? When I try to print the value of "overlay", I get "object Object"...

listener_rightclick = GEvent.addListener(map, 'singlerightclick', function(point, src, overlay){
 if (overlay){
  document.getElementById('test').innerHTML = 'cliqué ! ' + overlay;
  GEvent.removeListener(listener_rightclick);
  map.removeOverlay(overlay);
  ecouter_clicks_pts();
 }
 //document.getElementById('pt_latlng').innerHTML = 'xxxxxxxxxxxx: '+overlay;
});
+1  A: 

If this is only for debugging purposes, I'd use Firebug: http://getfirebug.com/

To print the array contents to the debugging console, all you have to do is:

console.log(overlay);
brianreavis
A: 
var obj = {
    name:'john'
}

function inspect( obj ) {
    for ( var prop in obj ) {
        if ( obj.hasOwnProperty( prop ) ) {
            console.log( prop + ':' + obj[prop] );
        }
    }
}

inspect( obj )

Assuming you have Firebug installed, this is one way to inspect an object.

meder
Firebug has a built-in object inspector already. Why would you need to loop over properties manually?
Crescent Fresh
A: 

Ok thanks guys! But what I was looking for was this :

option #1 : toSource() function

document.getElementById('info_div').innerHTML = GMarker.toSource();

Option #2 : for ... in function

var info;
for (x in GMarker){info = info + '   ' + x}
document.getElementById('info_div').innerHTML = info;
Rock