I've looked a lot of examples but I couldn't find anything to solve my problem. I have json array with following format ;
{ "value" : [
{ "...some variables...",
"comments" : [
{ "user_name" : "arascanakin",
"picture_url" : "...some url..."
}
],
"error" : false,
"msg" : "some message"
}
P.S. There may be syntax errors, I've written the JSON array manually. It's right.
I have the following jQuery to iterate over arrays:
$.each($task_array, function (i, task)
{
// some stuff
$.each(task.comments, function(i, $task_comment)
{
// some stuff
// $task_comment is undefined here
});
});
The problem is task.comments is undefined when I set each comment element to $task_comment.
Any ideas to solve this problem? It seems correct to me but I read that JavaScript doesn't allow multidimensional arrays.
task.commentsis an array, then$task_commentwill be the value of the array entry: jsfiddle.net/7yJkG. It seems the data is not like you think it is, double check it.tsk = task.comments; for(var i = 0; i < tsk.length; i++) { //do something with tsk[i]; }$task_comment.user_nameand$task_comment.contentgives the right values, but I still get this error; Cannot read property 'length' of undefined line_no : second each iteration @FelixKling