[Solved] Rearranging JavaScript string components [closed]


function objectify(str) {
    var obj = {},
        arr = str.split('|');
    for (i=0; i<arr.length;i++) {
        var parts = arr[i].split(',');
        obj[parts[0]] = parts[1];
    }
    return obj;
}

FIDDLE

Create an empty object, split the string on | and iterate over the parts, split again on comma, and use the result as key/value pairs in the object, and return the object when done.

13

solved Rearranging JavaScript string components [closed]