Reputation: 4302
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 and returns:
Upvotes: 0
Views: 111
Reputation: 42870
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.
Upvotes: 2
Reputation: 3958
your array is a string. use:
var myarray = eval('["hello", "helloe", "helloer"]');
Upvotes: 1