how to alert javascript object

Viewed 49052

I am trying to study the jquery class, but I have a hard time debugging an object because I can't see the element inside of it

$("#birds").autocomplete({
    source: "search.php",
    select: function (event, ui) {
        alert(ui);
    }
});

it returns [object Object].. :( My question is how can I alert the object so that I can see the element?

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

Convert your array or object to a JSON object using stringify.

Example:

var obj = { "name":"bayiha", "age":30, "city":"Eseka"};
var myJSON = JSON.stringify(obj);

alert(myJSON);

for more info clik here

Related