214098/calculate-string-value-in-javascript-not-using-eval
Is there a JavaScript method other than eval() for calculating a formula contained in a string?
Normally, I'd take action similar to
var apa = "12/5*9+9.4*2"; console.log(eval(apa));
So, does anyone know of any eval() alternatives?
You could use the Function() constructor:
function evil(fn) { return new Function('return ' + fn)(); } console.log(evil('12/5*9+9.4*2')); // => 40.4
You can use string.indexOf('s'). If the 's' is present in string, ...READ MORE
Use java.util.Arrays: String res = Arrays.toString(array); System. ...READ MORE
Here is the code I am using. ...READ MORE
Hey, @Pooja, Before starting with anything you should ...READ MORE
The eval() function evaluates an expression, but "5+5" is a string, ...READ MORE
Use the Docker Engine Api:Docker Engine API ...READ MORE
I don't think you can achieve this ...READ MORE
This quote rightly explains that 2 totally ...READ MORE
Here's how to draw a circle in ...READ MORE
This is what I've found to be ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.