Reputation: 559
i have var value="10+10"
when i try to convert this using parseInt(value)
to an int it is giving me NaN
. Is their any option to convert a string if it has special characters in it?
The Result shoud be 20
or simply 10+10
Upvotes: 0
Views: 500
Reputation: 41447
you can use eval to evaluate string operations.
since parseInt doesn't recognize characters like +
it will return the numbers until special characters.
as a example
(parseInt("10+10")
print 10 and
(parseInt("100+10")
print 100 and
console.log(parseInt("10+10"))
console.log(parseInt("100+10"))
console.log(eval("10+10"))
console.log(eval("10*10"))
Upvotes: 1