Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
191
rated 0 times [  193] [ 2]  / answers: 1 / hits: 19235  / 12 Years ago, wed, february 6, 2013, 12:00:00

Is there any way to convert a string to an expression?



my string: var1 == null && var2 != 5



I want to use this string as a condition of the if(), Like if(var1 == null && var2 != 5)


More From » javascript

 Answers
56

Use eval. This will do



if (eval( var1 == null && var2 != 5))
{
}

[#80393] Monday, February 4, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
felixa

Total Points: 180
Total Questions: 113
Total Answers: 108

Location: Palau
Member since Sat, Aug 21, 2021
3 Years ago
;