-2
Hello, I wonder if there’s any way I can get the value +
in the middle if a string
and leave him as a operator ?
Example:
Of:
var string = "15 + 20 + 30"
To:
var convert = "15" + "20" + "30"
Obs: the amount of values inside is undefined can be "15 + 15"
or even "1 + 1 + 1 + 1 + 1 + 1 + 1"
You can do something really simple like
'1 + 1 + 1 + 1 + 1 + 1 + 1'.split('+').reduce((a,b) => parseInt(a) + parseInt(b), 0)
– MarceloBoni