JS has no built-in functionality to do that.
But u can use a little helper-method.
function setProp(obj, prop, value){
var s = String(prop),
a = s.replace("[", "][").split("]["),
last = a.length - 1,
p, q;
if(last && s.substr(-1) === "]"){
p = a[last];
a[last] = p.substr(0, p.length-1);
}
for(var i=0, me = obj; i<last; ++i){
var p = a[i];
//check if property is not a primiive or undefined
var hasProp = p in me && me[p] === Object(me[p]);
if(!hasProp){ //create a object for it
q = a[i+1];
//use an Array for numeric indices
me[p] = (q === (+q).toString())? []: {};
//always use Objects
//me[p] = {};
}
me = me[p];
}
me[a[last]] = value;
}
var config = { a: 2 };
setProp(config, 'b[1]', 9);
setProp(config, 'b[2]', 8);
setProp(config, 'c[test]', 3);
Be careful with your strings, the parser is pretty basic
It assumes the input string to be valid.