Use reduce()
var myArr = ['foo', 'bar', 'baz'];
var myObj = {};
myArr.reduce(function(a, b) {
a[b] = {};
return a[b];
}, myObj);
console.log(myObj);
More Related Contents:
- Sorting array of object based on range of Numbers of String [closed]
- Convert string into several integer arrays [duplicate]
- Sort out array of object using its value [duplicate]
- Sort array of objects by string property value
- How to sort an array of objects by multiple fields?
- How to sort 2 dimensional array by column value?
- What is the stability of the Array.sort() method in different browsers?
- How can I convert the “arguments” object to an array in JavaScript?
- How to sort array inside collection record in MongoDB?
- Sort an array of object by a property (with custom order, not alphabetically)
- Sorting objects by property values
- Javascript sort function. Sort by First then by Second
- sort Javascript array by two numeric fields
- How to sort an associative array by its values in Javascript?
- Sort an array with arrays in it by string
- What is the most efficient way to sort an Html Select’s Options by value, while preserving the currently selected item?
- Sort an array based on another array of integers
- How to sort an array based on the length of each element?
- Sort array containing objects based on another array [duplicate]
- Does .sort function change original array?
- Reordering arrays
- Javascript array sort and unique
- Sort an array to have specific items first in the array
- Javascript – sorting array by multiple criteria
- Sort an array of objects by multiple properties
- Sorting an Array of JavaScript Objects a Specific Order (using existing function)
- Sort a Javascript Array by frequency and then filter repeats
- Why doesn’t the sort function of javascript work well?
- How does one sort a multi dimensional array by multiple columns in JavaScript?
- How to sort a JavaScript array of objects by nested object property?