how can I split a string such as
'11+4+3'
into ['11', '+', '4', '+', '3']
?
or even turn array of
[1, 1, '+', 4, '+', 3]
into [11, '+', 4, '+', 3]
?
splitting the string with regexp of
/[^0-9]/g
will split into numbers I want but will remove the operation values. I need a way so that I can keep the operation values as well. I also know that eval()
of the string will automatically add the string values into number values but I'm trying to figure out how to add the string of numbers and operations without using eval()
.