This question has already been answered:

for example, there is the string sin (x ^ 2) how to convert it to Math.sin (pow (x, 2))

Reported as a duplicate by Suvitruf members , Grundy javascript Aug 18 '18 at 5:01 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    There is a mathjs library

    You can execute expressions in it:

    math.eval('sqrt(3^2 + 4^2)') // 5 math.eval('sqrt(-4)') // 2i math.eval('2 inch to cm') // 5.08 cm math.eval('cos(45 deg)') // 0.7071067811865476 

    Sandbox where you can try