Search code examples
javascriptstringtransformoperation

Transform string into operation


I need to transform a string like "5+4+8*6(4)" as an operation, after it, I will be able to calculate it (here 5+4+8*6(4) = 201)


Solution

  • I advise you to use the mathjs library http://mathjs.org/docs/expressions/parsing.html

    var result = math.eval('5+4+8*6(4)');