0

I have a variable (var a='10+8-2'). Now i want mathematical operation in the string, That means var a=16 .

Apon Ahmed
  • 53
  • 1
  • 9
  • If you want function, `substr` or `substring`. What is the question? – Tushar Sep 03 '15 at 04:50
  • 1
    Your title seems to be asking a completely different question than the text of the question. What does evaluating a formula have to do with the PHP function `substr()`? – Barmar Sep 03 '15 at 04:51

1 Answers1

1

javascript has eval for this operation

Try like this

var a=eval('10+8-2');

but eval is evil during minification

Read this before using it

https://stackoverflow.com/a/198031/4161269

Community
  • 1
  • 1
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80