I've a simply loop in node.js:
exports.sample = function (req, res) {
var images = req.query.images;
images.forEach(function (img) {
console.log(img);
console.log(img.path, img.id);
console.log(img);
});
res.end();
};
The result is:
{"id":42,"path":"gGGfNIMGFK95mxQ66SfAHtYm.jpg"}
undefined undefined
{"id":42,"path":"gGGfNIMGFK95mxQ66SfAHtYm.jpg"}
I can access the properties in the client side but not on the server side.
Can someone help me to understand what's happening? Why can't I access my object properties?
objectorstringimg = JSON.parse(img)before logsimgwere an object then the console output would be more likeObject {id: 42, path: "gGGfNIMGFK95mxQ66SfAHtYm.jpg"}. What you've posted is a string.