开发者

How do I make this loop through an array?

I have this jquery code:

function(returnArray){
     for (i=0; i<returnArray.length; i++) {
         $('<li class="tagSuggestTag"/>').appendTo('#tagSuggest ul').text(returnArray[i]);
     }

return array is an array, but for some reason when I do this it loops through every letter of the array instead of each value in the array.

The returnArray is ["hello", "helloe", "helloer"] and that loop goes through a开发者_JAVA百科nd returns:

How do I make this loop through an array?


It was revealed in the comments to the question that the returnarray isn't really an array, it's a JSON string representation of a string computed by the PHP function json_encode().

The function jQuery.parseJSON can turn this back into a javascript array.


your array is a string. use:

var myarray = eval('["hello", "helloe", "helloer"]');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜