0

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;
});

3 Answers 3

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0
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.

1 Comment

Firebug has a built-in object inspector already. Why would you need to loop over properties manually?
0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.