开发者

Converting string "true" / "false" to boolean value [duplicate]

This question already has answers here: How can I convert a string to boolean in JavaScript? (103 answers) Closed 9 years ago.

I have a 开发者_StackOverflowJavaScript string containing "true" or "false".

How may I convert it to boolean without using the eval function?


var val = (string === "true");


You could simply have: var result = (str == "true").


If you're using the variable result:

result = result == "true";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜