开发者

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

开发者 https://www.devze.com 2023-01-20 19:02 出处:网络
This question already has answers here: How can I convert a string to boolean in JavaScript? (103 answers)
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

精彩评论

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

关注公众号