Converting string "true" / "false" to boolean value
JavascriptBooleanJavascript Problem Overview
I have a JavaScript string containing "true"
or "false"
.
How may I convert it to boolean without using the eval
function?
Javascript Solutions
Solution 1 - Javascript
var val = (string === "true");
Solution 2 - Javascript
You could simply have: var result = (str == "true")
.
Solution 3 - Javascript
If you're using the variable result:
result = result == "true";