This sounds like a simple task, but I can\'t quite figure it out: I have an array :
var array = [\'opt1\',\'sub1\',\'subsub1\',\'subsubsub1\']
You can use reduceRight to transform the array into a 'chain' of objects:
const array = ['a', 'b', 'c']; const object = array.reduceRight((obj, next) => ({[next]: obj}), {}); // Example: console.log(object); // {"a":{"b":{"c":{}}}}