I have a input in below format and contain only numbers not alphabets: arr = ['1 2 3 4 5 6']
I want to split all the numbers in below format:
arr = [1,2,3,4,5,6]
Can do it like so
arr[0].split(' ').map((n) => parseInt(n))
If array could contain multiple similar strings like so ['1 2 3 4', '5 6 7 8']
['1 2 3 4', '5 6 7 8']
arr.map((string) => { string.split(' ').map((n) => parseInt(n)) }).flat();
2.1m questions
2.1m answers
60 comments
57.0k users