I have this little example:
var myoperation = "2+2";
var myoperation2="2*5/3";
var myoperation3="3+(4/2)"
is there anyway to execute this and get a result?
Thanks a lot in advance!
Use eval MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/eval
Some people say it is evil, but it was designed for this exact purpose;
console.log(eval(myoperation)); // 4
console.log(eval(myoperation2)); // 3.33
console.log(eval(myoperation3)); // 5
eval() is dangerous, but in JavaScript... whats the worst that could happen?
eval, which is also evil.eval()seems to work just fine. However, unless it is used very judiciously and cautiously, it would really break your code.