In my app.js, I have the following:
post.find({'global': true}).sort('date').exec(function(err, data) {
for (var i = 0; i <= data.length; i++) {
console.log(data[i].email);
//socket.emit('Post', {name: data[i].name, cont: data[i].cont, date: data[i].date});
}
});
When I use
console.log(data[i]);
I get my data in the form of
{name: blah, cont: blah, email: blah, etc}
But when i try emitting the data
data[i].attribute
I get the error
TypeError: Cannot read property 'attribute' of undefined
I know the data is there, as I am able to log it in the console. Why can't I access the specific attribute of the array? Any ideas?