I've the following string in the JavaScript:
test: hi,
otherTest: hiAgain
How can I transform in a key: value array?
var string = 'test: hi,otherTest: hiAgain';
var sets = string.split(","); //splits string by commas
var out = new Array(); //prepare the output array
for (var i=0; i<sets.length; i++) {
var keyval = sets[i].split(":"); //split by colon for key/val
out[keyval[0]] = keyval[1].trim(); //trim off white spaces and set array
}
push to the array
splitto separate the string on the commas but I don't know how to do separate in a key: value array.