Home > Blockchain >  Convert a simple array to a two dimensional array of objects
Convert a simple array to a two dimensional array of objects

Time:11-17

I want to convert this:

[null, 1890, null, NGU]

...into this:

[[], [1890], [], [NGU]]

I've tried creating a new array and pushing values to it, but that just ends up looking the same. Honestly, I'm unsure of what to even call what I'm trying to create. Is it a two-dimensional array or an array of objects?

This is for a google app script and the documentation calls it a two-dimensional array of values.

CodePudding user response:

var arr = [null, 1890, null, 'NGU']
var arr2d = arr.map(x => [x])

console.log(arr2d) // output --> [ [ null ], [ 1890 ], [ null ], [ 'NGU' ] ]
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related