While responding to a SO question, I wrote the following method to convert a flat key structure to a hierarchical one as given belowIn{   property1: 'value1',   property2.property3: 'value2',   property2.property7: 'value4',   property4.property5.property6: 'value3',}Out{    property1: 'value1',    property2: {        property3: 'value2',        property7: 'value4'    },    property4: {        property5: {            property6: 'value3'        }    }}Converter:function convert(obj) {    var res = {}, i, j, splits, ref, key;    for (i in obj) {        if (obj.hasOwnProperty(i)) {            splits = i.split('.');            ref = res;            for (j = 0; j < splits.length; j++) {                key = splits[j];                if (j == splits.length - 1) {                    ref[key] = obj[i];                } else {                    ref = ref[key] = ref[key] || {};                }            }        };    }    return res;}Can this be improved?Demo: Fiddle
Convert flat object keys to hierarchical one
javascript