-6
I want to split the number PI 3.141593 into an array that does not contain '.' and all separate numbers. I tried to split . split(/[ .""]/g) but it didn’t work. What would be the equivalent solutions avoiding brute force?
-6
I want to split the number PI 3.141593 into an array that does not contain '.' and all separate numbers. I tried to split . split(/[ .""]/g) but it didn’t work. What would be the equivalent solutions avoiding brute force?
-2
Forehead there, here it worked:
const pi = 3.141593;
const piArray = pi.toString().replace(".", "").split("");
console.log(piArray);
If you need to mount a string and not an array, apply toString() to the piArray variable afterwards.
const pi = 3.141593;
const piArray = pi.toString().replace(".", "").split("");
console.log(piArray.toString());
Browser other questions tagged javascript regex
You are not signed in. Login or sign up in order to post.
On a line without regex (which is probably not the right tool for this type of operation):
[...Math.PI.toString().replace('.', '')];
.– Luiz Felipe