Javascript array to multi level Object -


i have array in javascript , need convert multi-level object. example: input :

var myarray = ["abc", "def", "ghi"] ; 

output want :

var myobj = {abc:{ def: { ghi: {} } }}; 

what efficient way achieve javascript ?

you can use reduce() , pass empty object accumulator.

var myarray = ["abc", "def", "ghi"] ;  var obj = {}     myarray.reduce((r, e) => r[e] = {}, obj);  console.log(obj)


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -