I am working in node.js.
I make a rest api call in .js file as follows:
$http.get("/api/products/"+cat_id).success(
function(response){
//$scope.cat_id = response;
console.log("Got response products for page 1");
console.log("Received products for cat :"+response.pdt.cat_id);
}
)
The following code snippet is contained in a file app.js:
app.get('/api/products/:cat', function(req, res){
var pdts = [];
for(var i=0; i<=6; i++){
var pdt = {
id : "1" + i
, name: 'Product' + i
,cat_id: req.params.cat
};
pdts.push(pdt);
}
res.json(pdts);
});
The array of objects pdts is sent as a response through the last statement.
Now how do I access the individual attributes of my object pdt??
The result of
console.log("Received products for cat :"+response.pdt.cat_id);
is
Cannot read property 'cat_id' of undefined
response[0].cat_id