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:
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"]');
精彩评论