I have a dynamically generated array done by PHP sent to Javascript. It's basically an array of unread messages. It contains the sender's name and the messages that they have sent.
Given that I do not know the names, how do I retrieve their names and their messages?
{"Emma Giles":
[{"message":"Hi Phil","date":"Tue 10 May 2:55 PM 2011"}],
"Johnathan Macmanners":
[{"message":"Hi Emma","date":"Sun 26 June 10:03 PM 2011"}],
"Ellen Murley":
[{"message":"Hello","date":"Fri 04 May 4:05 PM 2012"},
{"message":"How are you?","date":"Fri 04 May 2:52 PM 2012"}],
"Amanda Patterson":
[{"message":"test","date":"Fri 27 April 10:07 AM 2012"}],
"ALEX Pell":
[{"message":"Hi Alvon","date":"Mon 05 March 10:07 AM 2012"}]}
I have tried this but it only prints out numbers for some reason and I've replaced key with val and it prints out every single character in the array one by one.:
$.each(data, function(key, val)
{
console.log(key);
});
data[0]becausedatais a dictionary, not a regularArray. Again, I don't see anything wrong in particular with the code you started with.