var stringToSplit = "10000.9409.13924.11025.10000._.11025.13225._.9801.12321.12321.11664.";
//Finished result should be:
result == ["10000.", "9409.", "13924.", "11025.", "10000.", "_.", "11025.", "13225.", "_.", "9801.", "12321.", "12321.", "11664."]
After each "." I want to split it and push it into an array.
asked May 23, 2020 at 9:11
user12059608
-
What have you tried so far to solve this on your own?Andreas– Andreas2020年05月23日 09:15:09 +00:00Commented May 23, 2020 at 9:15
5 Answers 5
You split it, and map over. With every iteration you add an . to the end
var stringToSplit = "10000.9409.13924.11025.10000._.11025.13225._.9801.12321.12321.11664.";
let result = stringToSplit.split(".").map(el => el + ".");
console.log(result)
answered May 23, 2020 at 9:15
Ilijanovic
15k4 gold badges29 silver badges63 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You could match the parts, instead of using split.
var string = "10000.9409.13924.11025.10000._.11025.13225._.9801.12321.12321.11664.",
result = string.match(/[^.]+\./g);
console.log(result);
answered May 23, 2020 at 9:15
Nina Scholz
388k26 gold badges367 silver badges417 bronze badges
Comments
var stringToSplit = "10000.9409.13924.11025.10000._.11025.13225._.9801.12321.12321.11664.";
var arr = stringToSplit.split(".").map(item => item+".");
console.log(arr);
answered May 23, 2020 at 9:16
Argee
1,2341 gold badge12 silver badges23 bronze badges
Comments
split the string using . delimiter and then slice to remove the last empty space. Then use map to return the required array of elements
var stringToSplit = "10000.9409.13924.11025.10000._.11025.13225._.9801.12321.12321.11664.";
let newData = stringToSplit.split('.');
let val = newData.slice(0, newData.length - 1).map(item => `${item}.`)
console.log(val)
answered May 23, 2020 at 9:23
brk
50.3k10 gold badges59 silver badges85 bronze badges
Comments
you could use a lookbehind with .split
var stringToSplit = "10000.9409.13924.11025.10000._.11025.13225._.9801.12321.12321.11664.";
let out = stringToSplit.split(/(?<=\.)/);
console.log(out)
answered May 23, 2020 at 9:34
arizafar
3,1321 gold badge11 silver badges19 bronze badges
Comments
lang-js