how to alert javascript object

Just convert your object to a JSON object using stringfy.

alert(JSON.stringify(yourObjectVariable));

simple as pie :)


i recommend you use FireBug for debugging javascript. then you can just do

console.log(ui) 

and it'll log the object in a form you can expand


you can also try Java Script method:

 // Alert javascript object in alert box
    function alertObject(obj){      
        for(var key in obj) {
        alert('key: ' + key + '\n' + 'value: ' + obj[key]);
        if( typeof obj[key] === 'object' ) {
            alertObject(obj[key]);
        }
        }
    }

Here 'obj' is:

// your object var
var getObject = {};

// object set with key an val
getObject.swfVersionStr = '10.0';
getObject.xiSwfUrlStr = null;
getObject.flashvarsObj = {};
getObject.parObj = {allowfullscreen: "true",wmode: "window",menu: "false"};

Call like this:

alertObject(getObject );

So, simple.. :)


alert(JSON.stringify(YOUR_OBJECT_HERE, null, 4));

Tags:

Javascript