1
How to create a nested javascript object from a literal array?
I have the following array:
var x = ['a','b','c'];
From the array 'x' I would like to generate the following object:
var y = {a:{b:{c:{}}}};
So far I’ve tried to iterate within a loop. But I can’t find a way to validate whether the result already exists or not, nor put in the correct position, one key inside another.
Take a look at the underscore.js. library It makes array treatments a lot easier.
– Thiago Dorneles