“JS parse boolean” Kod odpowiedzi

Konwertuj ciąg na boolean js

var myBool = Boolean("false");  // == true

var myBool = !!"false";  // == true
Breakable Barracuda

Ciąg do boolean javascript

let toBool = string => string === 'true' ? true : false;
// Not everyone gets ES6 so here for the beginners
function toBool(string){
	if(string === 'true'){
      return true;
    } else {
      return false;
    }
}
NotDamian

Konwertuj ciąg true na boolean true javascript

stringToBoolean: function(string){
    switch(string.toLowerCase().trim()){
        case "true": case "yes": case "1": return true;
        case "false": case "no": case "0": case null: return false;
        default: return Boolean(string);
    }
}
Rich Rat

JS String to Boolean

// Do
var isTrueSet = (myValue == 'true');
// Or
var isTrueSet = (myValue === 'true');
Cybernated Dev

JS parse boolean

var isTrueSet = (myValue === 'true');
Dangerous Dog

JS Parse Bool

function parseBool(value) {
    if (typeof value === "string") {
        value = value.toLowerCase();
        if (value === "true" || value === "false") {
            return value === "true";
        }
    }
    return; // returns undefined
}
Lazar

Odpowiedzi podobne do “JS parse boolean”

Pytania podobne do “JS parse boolean”

Więcej pokrewnych odpowiedzi na “JS parse boolean” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu