I just want to add objects inside objects dynamically using array technique. I know how do we add Objects - those are Object[key] or Object.key but suppose I thing I have to add multiple objects dymanically using function
Note: below example is just for demonstration
let array = ['first','second','third']
let object = {}
function addObject(key) {
object[key] = "someValue"
}
for (var i = 0; i < array.length; i++) {
addObject(array[i])
}
This gives output like this { first: 'someValue', second: 'someValue', third: 'someValue'}. Actually I want my output something like nested object {first:{second:{third:'somevalue'}}} not exactly this but a nested object first > second > third.
My Actual question is like how to add objects inside object in this situation. What is the correct syntax for this. Like object[first][second][third] is standard way to achieve but I can't add + operator in the left side or calling array(['first.second.third'])
`
function addObject(key) {
object[key] + [key] = "someValue"
}
or calling
array(['first.second.third'])