How to convert string into boolean?

This question already has an answer here: How can I convert a string to boolean in JavaScript? 71 answers Try <div id='test' data-nav='true'> var truefalse = $('#test').data('nav'); .data should be able to evaluate it as boolean here is an example in JSFiddle https://jsfiddle.net/lismore/hx3gLvgw/

如何将字符串转换为布尔值?

这个问题在这里已经有了答案: 如何在JavaScript中将字符串转换为布尔值? 71个答案 尝试 <div id='test' data-nav='true'> var truefalse = $('#test').data('nav'); .data应该能够将其评估为布尔值 这里是JSFiddle中的一个例子https://jsfiddle.net/lismore/hx3gLvgw/

String to Boolean

This question already has an answer here: How can I convert a string to boolean in JavaScript? 71 answers 是不是: var FeatureFlag = _.extend(CommonConfig, { demoFeature: "true" == CommonConfig.getFeatureFlags['analytics.demo'], });

字符串到布尔值

这个问题在这里已经有了答案: 如何在JavaScript中将字符串转换为布尔值? 71个答案 是不是: var FeatureFlag = _.extend(CommonConfig, { demoFeature: "true" == CommonConfig.getFeatureFlags['analytics.demo'], });

how we can covert a string to boolean?

Possible Duplicate: How can I convert a string to boolean in JavaScript? I have a select list with 2 options in it, yes or no , something like: <select size="1"> <option value="true">yes</option> <option value="false">no</option> </select> Now i want to use the selected value in the jquery-UI button disabled property , means : $("button

我们如何将一个字符串转换为布尔值?

可能重复: 如何在JavaScript中将字符串转换为布尔值? 我有一个选择列表,其中有2个选项, yes或no ,如下所示: <select size="1"> <option value="true">yes</option> <option value="false">no</option> </select> 现在我想使用jquery-UI按钮禁用属性中的选定值,表示: $("button").button({ disabled : $("select").val() }); 现在我的问题是,我们将通过$

Converting a string into a boolean

Possible Duplicate: How can I convert a string to boolean in JavaScript? I have a hidden field that contains a boolean value, I am checking if it's true or false in a JavaScript function, like this: if (Trim(document.forms['mainform'].hiddenfield.value) == 'true') { } which I think is a lame way to do this. How to convert that string value into a boolean? This may seem a bit silly, b

将字符串转换为布尔值

可能重复: 如何在JavaScript中将字符串转换为布尔值? 我有一个包含布尔值的隐藏字段,我正在检查JavaScript函数中的true或false,如下所示: if (Trim(document.forms['mainform'].hiddenfield.value) == 'true') { } 我认为这是一个蹩脚的方式来做到这一点。 如何将该字符串值转换为布尔值? 这可能看起来有点愚蠢,但是你可以为String添加一个方法。 String.prototype.isTrue = function() { return this.toLowe

remove double quotes from string using javascript

This question already has an answer here: How can I convert a string to boolean in JavaScript? 71 answers I think you should consider why the value is "false" instead of false instead. Where is that value assigned, and is there any reason why you can't assign it as a proper boolean? Otherwise you can do something like this: function isStrTrueOrFalse(string) { return !strin

使用javascript从字符串中删除双引号

这个问题在这里已经有了答案: 如何在JavaScript中将字符串转换为布尔值? 71个答案 我认为你应该考虑为什么价值是“假”而不是假。 该值分配在哪里,是否有任何理由不能将其分配为适当的布尔值? 否则,你可以做这样的事情: function isStrTrueOrFalse(string) { return !string.toLowerCase().match(/false/);} 这样,任何“false”的字符串都会返回false。 任何其他字符串返回true。 这是因为“str”是真的。 不管内

Cleanest way to convert to boolean

This question already has an answer here: How can I convert a string to boolean in JavaScript? 71 answers Yes, you can always use this: var tata = Boolean(toto); And here are some tests: for (var value of [0, 1, -1, "0", "1", "cat", true, false, undefined, null]) { console.log(`Boolean(${typeof value} ${value}) is ${Boolean(value)}`); } Results: Boolean(number 0) is false Boolean(nu

最干净的方式来转换为布尔值

这个问题在这里已经有了答案: 如何在JavaScript中将字符串转换为布尔值? 71个答案 是的,你总是可以使用这个: var tata = Boolean(toto); 这里有一些测试: for (var value of [0, 1, -1, "0", "1", "cat", true, false, undefined, null]) { console.log(`Boolean(${typeof value} ${value}) is ${Boolean(value)}`); } 结果: Boolean(number 0) is false Boolean(number 1) is true Boolean(number -1) is tr

Cast a bool in JavaScript

Possible Duplicate: How can I convert a string to boolean in JavaScript? Hi, How can I cast a String in Bool ? Example: "False" to bool false I need this for my JavaScript. Thank you for help ! function castStrToBool(str){ if (str.toLowerCase()=='false'){ return false; } else if (str.toLowerCase()=='true'){ return true; } else { return undef

在JavaScript中投射一个布尔

可能重复: 如何在JavaScript中将字符串转换为布尔值? 嗨, 如何在Bool中投射字符串? 例如:“假”来布尔假 我需要这个用于我的JavaScript。 谢谢你的帮助 ! function castStrToBool(str){ if (str.toLowerCase()=='false'){ return false; } else if (str.toLowerCase()=='true'){ return true; } else { return undefined; } } ......但我认为乔恩的回答更好! 你可以这

Convert string to Boolean in javascript

This question already has an answer here: How can I convert a string to boolean in JavaScript? 71 answers 我会在这里使用一个简单的字符串比较,据我所知,没有内置函数用于你想要做的事情(除非你想诉诸eval ...你不这样做)。 var myBool = myString == "true"; I would like to answer this to improve upon the accepted answer. To improve performance, and in real world cases where form inputs might be

在javascript中将字符串转换为布尔值

这个问题在这里已经有了答案: 如何在JavaScript中将字符串转换为布尔值? 71个答案 我会在这里使用一个简单的字符串比较,据我所知,没有内置函数用于你想要做的事情(除非你想诉诸eval ...你不这样做)。 var myBool = myString == "true"; 我想回答这个问题以改进已接受的答案。 为了提高性能,并且在现实世界中,表单输入可能会传递像'true'或'false'这样的值,这种方法会产生最好的结果。 function

JavaScript: Parsing a string Boolean value?

This question already has an answer here: How can I convert a string to boolean in JavaScript? 71 answers I would be inclined to do a one liner with a ternary if. var bool_value = value == "true" ? true : false Edit: Even quicker would be to simply avoid using the a logical statement and instead just use the expression itself: var bool_value = value == 'true'; This works because value ==

JavaScript:解析一个字符串布尔值?

这个问题在这里已经有了答案: 如何在JavaScript中将字符串转换为布尔值? 71个答案 如果是的话,我会倾向于用一个三元组来做一个班轮。 var bool_value = value == "true" ? true : false 编辑:更快速的是简单地避免使用逻辑语句,而只是使用表达式本身: var bool_value = value == 'true'; 这是可行的,因为value == 'true'是根据value变量是否为'true'的字符串来计算'true' 。 如果是,

converting String true/false to Boolean value

This question already has an answer here: How can I convert a string to boolean in JavaScript? 71 answers var val = (string === "true"); 你可以简单地使用: var result = (str == "true") 。 如果您使用变量结果: result = result == "true";

将字符串true / false转换为布尔值

这个问题在这里已经有了答案: 如何在JavaScript中将字符串转换为布尔值? 71个答案 var val = (string === "true"); 你可以简单地使用: var result = (str == "true") 。 如果您使用变量结果: result = result == "true";