I have this Javascript object
var output = {
"_resolved": true,
"_result": [ {
"title": "Pencil",
"quantity": 1,
"objectId": "HknL2ZAspb"
} ]
}
When I try to get the value of title like this:
output._result[0].title
it returns undefined.
However
output._result[0]
correctly returns
{ "title": "Pencil", "quantity": 1, "objectId": "HknL2ZAspb" }
Any idea why output._result[0].title returns undefined?
I also tried output["_result"][0]["title"] but it returns undefined too.
var output = {
"_resolved": true,
"_result": [ {
"title": "Pencil",
"quantity": 1,
"objectId": "HknL2ZAspb"
} ]
}
console.log(output._result[0].title);
Serverside code (Node):
const productsQuery = new Parse.Query(ProductTable);
output = productsQuery.get('HknL2ZAspb'); //objectID
app.get('/', (req, res) => res.send(JSON.stringify(output["_result"][0]["title"])))
Note the Query and other code is just fine. As output returns the exact object.
output._result[0].titleworks correctly with the data you provided. You must have a typo in your code.