console.log(result) returns [object Object]. How do I get result.name? [duplicate] console.log(result) returns [object Object]. How do I get result.name? [duplicate] arrays arrays

console.log(result) returns [object Object]. How do I get result.name? [duplicate]


Use console.log(JSON.stringify(result)) to get the JSON in a string format.

EDIT: If your intention is to get the id and other properties from the result object and you want to see it console to know if its there then you can check with hasOwnProperty and access the property if it does exist:

var obj = {id : "007", name : "James Bond"};console.log(obj);                    // Object { id: "007", name: "James Bond" }console.log(JSON.stringify(obj));    //{"id":"007","name":"James Bond"}if (obj.hasOwnProperty("id")){    console.log(obj.id);             //007}


Try adding JSON.stringify(result) to convert the JS Object into a JSON string.

From your code I can see you are logging the result in error which is called if the AJAX request fails, so I'm not sure how you'd go about accessing the id/name/etc. then (you are checking for success inside the error condition!).

Note that if you use Chrome's console you should be able to browse through the object without having to stringify the JSON, which makes it easier to debug.