Splitting a string into words has resulted in splitting into letters
javascript, jquery
Solution
If `data` is your string, then parse it from JSON to a JavaScript array of strings, then iterate over that:
var yourArray = JSON.parse(data);
$.each(yourArray, function(index, value) {
$('#bu_group').append($('<option/>', {
value: value,
text : value
}));
});
Problem
I'm new to Javascript. I need to split a string of this format: ``` ["Man1","SKC2","fsdfds3","ETA4","Star5","SCity 6","TESTGB11"] ``` and create as options for select tag. I tried the below code ``` $.each(data, function (index, value) { $('#bu_group').append($('<option/>', { value: value, text : value })); }); ``` But I get strings split as letters. What can I do to split the string to get options as ``` <option>Man1</option> <option>SKC2</option> ``` Note : Some times this string may contain spaces as well.