I have been struggling with this problem the entire day. I feel like it's super solvable, and I'm not sure where I'm going wrong. Each time I go to post this, I feel like I come up with a different solution that doesn't end up working.
I'm looking to do the following:
var someObj = {};
// @param key - string - in the form of "foo-bar-baz" or "foo-bar".
// (i won't know the number of segments ahead of time.)
// @param value - string - standard, don't need to act on it
function buildObject( key, value ) {
var allKeys = key.split("-");
// do stuff here to build someObj
}
Essentially the key will always take the format of key-key-key where i want to build someObj[key1][key2][key3] = value.
This JSFiddle contains a longer example with a sample layout of the data structure I want to walk away with.
Thanks so much for any help you can give.