nested object values in js code example
Example 1: js create nested object from fields
function assign(obj, keyPath, value) {
lastKeyIndex = keyPath.length-1;
for (var i = 0; i < lastKeyIndex; ++ i) {
key = keyPath[i];
if (!(key in obj)){
obj[key] = {}
}
obj = obj[key];
}
obj[keyPath[lastKeyIndex]] = value;
}
Example 2: js create nested object from fields
var settings = {};
assign(settings, ['Modules', 'Video', 'Plugin'], 'JWPlayer');