I would like to do something which seems very easy but I haven't found the solution yet (I didn't find anything on the forum of course).
I want to separate one element of an array, in two.
For instance: I have an array
let array = [
[ '201026 21330', '12385', '852589', '951478' ],
[ '201026 21320', '12385', '369874' ]
]
I want to split the first element like that (notice the first elements, here separated):
let result =
[
[ '201026','21330', '12385', '852589', '951478' ],
[ '201026','21320', '12385', '369874' ]
]
Does anybody have any clue?
Thanks in advance
Use Array#map, String#split and Array#flat
const arr = [
[ '201026 21330', '12385', '852589', '951478' ],
[ '201026 21320', '12385', '369874' ]
]
const res = arr.map(row => row.map(item => item.split(' ')).flat());
console.log(res)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With