I have a hidden input box from which I\'m retrieving the comma-separated text value (e.g. \'apple,banana,jam\'
) using:
var searchTerms = $(\"#se
var array = searchTerms.split(",");
for (var i in array){
alert(array[i]);
}
var array = $('#searchKeywords').val().split(",");
then
$.each(array,function(i){
alert(array[i]);
});
OR
for (i=0;i<array.length;i++){
alert(array[i]);
}
use js split() method to create an array
var keywords = $('#searchKeywords').val().split(",");
then loop through the array using jQuery.each() function. as the documentation says:
In the case of an array, the callback is passed an array index and a corresponding array value each time
$.each(keywords, function(i, keyword){
console.log(keyword);
});