0
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
1
  • What have you tried so far to solve this on your own? Commented May 23, 2020 at 9:15

5 Answers 5

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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

Comments

1

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

Comments

1

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.