I have an array like this:
var array=[
['0000'],
['0000']
]
and I'd like to get a result like this:
var result=[
[0,0,0,0],
[0,0,0,0]
]
How is this possible with javascript map?
My solution with a stupid for loop looks like this:
var array=[
['0000'],
['0000']
]
var new_array=[]
for (var i=0; i<array.length;i++) {
new_array.push((array[i].toString().split('').map(Number)))
}
console.log(new_array)
Edit 1.0 How to get the same result if my array looks like this:
['0000','0000','0000']
Edit 2.0 Ok last edit - How to turn around the process? So getting from
[[0,0,0,0], [0,0,0,0]]-- >[['0000'], ['0000']]
EDIT 3 -- OK found the solution for Edit 2 on my own:
array.map(a => [a.join('')])
Thanks for your help.
Jonas
var new_array = array.map(x => x[0].split("").map(Number))?forloop?