var params = {
search: {
make: "",
model: ""
}
}
function setVariable() {
var value = "BMW";
var key = "search.make";
var arr = key.split("."); //eg. ["search", "make"]
params[arr[0]][arr[1]] = value; // this works, but how do you
// do it with unknown arr[] length?
}
How do I do this with an unknown arr[] length?
I have surmised that I probably need to do a recursive call, maybe passing something like arr.slice(1) within the function, but I have not been able to figure out what that should look like.
searchdoes not even exist? Would you want to create the object{make: value}then and assign it toparams.search? Or do you only want to be able to set the value for existing properties?