John Croneh John Croneh - 1 year ago 103
Javascript Question

JavaScript: Convert [a,b,c] into [a][b][c]

I have arrays like

and so on.

How can I convert them into
and so on?


var arr = [1,2,3,4];
arr = do(arr); // arr = arr[1][2][3][4]

Answer Source

You could map it with Array#map.That returns an array with the processed values.


console.log([1, 2, 3, 4].map(a => [a]));


console.log([1, 2, 3, 4].map(function (a) {
    return [a];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download