I'm trying to grab a series of strings from a JSON object and concatenate them into one big string. It seemed pretty obvious for me to just use a loop, adding each new string in every iteration of said loop. When I actually plugged it in, however, I get some odd errors.
TypeError: data.posts[i] is undefined
I would normally just assume that it can't be called like that (I'm new to javascript so I'm basing much of this upon educated guesses), but here's the weird thing: the logs I printed to firebug contain exactly the expected information. I could live with the unexplained error, but then it won't display the combined string on the web page.
var data = JSON.parse(d);
var i = 0;
while(i <= data["posts"].length) {
messages += "<b>" + data["posts"][i]['nickname']
+ ":</b> - " + data["posts"][i]['content'] + "<br>";
i++;
console.log(messages);
}
console.log(messages);
$('.post1').html(messages);
What exactly am I missing here?