How to execute an arithmetic operation inside a string in Javascript? -


i have little example:

var myoperation = "2+2"; var myoperation2="2*5/3"; var myoperation3="3+(4/2)" 

is there anyway execute , result?

thanks lot in advance!

use eval mdn: https://developer.mozilla.org/en-us/docs/javascript/reference/global_objects/eval

some people evil, designed exact purpose;

console.log(eval(myoperation)); // 4 console.log(eval(myoperation2)); // 3.33 console.log(eval(myoperation3)); // 5 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -