ess
ess

Reputation: 683

get data from array object in javascript

I am trying to get data from an object. I have tried to get the data as a.doc._id as given below.

function ab(data){alert("content is "+data.doc.id);}

enter image description here

Upvotes: 3

Views: 117

Answers (2)

Lee Gary
Lee Gary

Reputation: 2397

"doc" is not an object, as shown in the inspector, you should rename the property name to something like doc-title instead.

Otherwise, you should create the object something like this

var data = {
             "act" : "",
             "doc": {
                 "_id" : "9",
                 "title": "fghfgh"
             }
           };

Upvotes: 0

MD Sayem Ahmed
MD Sayem Ahmed

Reputation: 29166

You probably need to access the property using the square bracket notation. Try -

alert("sdf" + data["doc._id"]);

Upvotes: 4

Related Questions