var string = ":All;true:Yes;false: ";
var array = string.split(/:|;/);
var listItems = [];
for (var i = 0; i < array.length; i += 2 ) {
listItems.push({itemValue: array[i], itemText: array[i + 1]})
}
Notice that this will set "false" and "true" as string. Same for numbers if you have it. If you want save them with the proper types, you have to add a manual conversion. Something like:
function value(val) {
if (!isNaN(val))
return +val;
if (val === "true")
return true;
if (val === "false")
return false;
return val;
}
Therefore the line that push the object to the array will change as below:
listItems.push({itemValue: value(array[i]), itemText: array[i + 1]})