I am working with an array and trying to split two sets of data that are contained within one element of the array.
Take a look at the code below :
const array = ["1 Boston 4 11", "2 Florida 6 14\n3 Texas 5 12", "4 California 7 13"];
array.map(x => {
return (
console.log(x.split(" "))
)
});
The element array[1]
holds two sets of data: 2 Florida 6 14
and 3 Texas 5 12
. I need to separate these into different arrays, each containing one set of data from array[1]
.
This is the expected result :
[
"1",
"Boston",
"4",
"11"
]
[
"2",
"Florida",
"6",
"14"
]
[
"3",
"Texas",
"5",
"12"
]
[
"4",
"California",
"7",
"13"
]
Can anyone please assist me in finding a solution?