I have got a very large string, it contains about 13000 times different data of the same kind. I have now created a function to split this string into an array of 13000 elements. Now each element of those 13000 still consists out of different data seperated with spaces (it looks something like: 20.8967489 50.29868 3 9867 86983648
How can I create a 2 dimensional array storing 5 elements for each of the 13000 elements?
I have tried something like this:
function getValuableData(){
const fullData = [[]];
text.replace(' ',' ');
text.replace(' ',' ');
const data = text.split('a')
data.forEach(element => {
const singleData = element.split(' ')
fullData.concat(singleData)
});
}
3
Answers
I’d
map
this array and split each element:Let see how we can get a 2 dimensional array storing 5 elements for each using single for loop
getValuableData
functionIf you have spaces around your split character you can use
String::indexOf()
to navigate by spaces in a big string, faster than splitting by a regex: