The question should be reopened, Object.assign, spread, or similar in the duplicate question won't nest the properties. ['a','b','c','d'].reverse().reduce((acc, curr) => { if (acc) return { [curr]: { ...acc } }; return { [curr]: 'any value' }; }, null);
@AlexanderStaroselsky the link posted by Shreyas isn't the one used to close this question. See the link at the very top. The answer there does indeed nest the properties
['a','b','c','d'].reverse().reduce((acc, curr) => { if (acc) return { [curr]: { ...acc } }; return { [curr]: 'any value' }; }, null);