javascript - Creating a new 2D array from regular array -


if have javascript array:

a = ["12", "34", "56", "78"]; 

and want make new 2d array this:

b = [ ["12345678"], ["34567812"], ["56781234"], ["78123456"] ]; 

i know should pretty simple can't figure out... brain kinda slow today... :/

join string @ various pivot locations.

n = []; for(i = 0; < a.length; i++){     n.push(a.slice(i).join("") + a.slice(0,i).join("")); } 

this outputs:

[ "12345678", "34567812", "56781234", "78123456" ] 

i not whether having nested single element arrays in output mistake, if required add square brackets inside push.


Comments