I believe this is what you are looking for:
function assignByPath(obj,path,value){
if (path.length == 1) {
obj[path[0]] = value;
return obj;
} else if (obj[path[0]] === undefined) {
obj[path[0]] = {};
}
return assignByPath(obj[path.shift()],path,value);
}
$.fn.serializeObject = function(){
var obj = {};
$.each( this.serializeArray(), function(i,o){
var n = o.name,
v = o.value;
path = n.replace('[','.').replace('][','.').replace(']','').split('.');
assignByPath(obj,path,v);
});
return obj;
};
fon60 source
share