Get data from array object in javascript

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

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

enter image description here

+3
source share
2 answers

You probably need to access the property using the square brackets. Try it -

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

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

Otherwise, you must create an object similar to this

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

All Articles