I am trying to figure out how to split a string by a single character and use the javascript eval()
and then rejoin the string.
So I have a string that looks like this 2*2d8/2d8, I split the string by the /
like below
remDice.split("/").forEach(function (remDie) {
console.log(remDie);
});
This gives me the two different parts, but I can't seem to figure out how to do the next part which is split by the character d
and then eval()
the two parts. So that my final string would look something like 4d8/2d8
.
I am aware that you should avoid eval()
but that really isn't a concern with this project.
.forEach()
you could always do another.split()
call. Is this limited to one level of this type of input?