convert string to boolean js

106

convert string to boolean js -

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

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

convert string true to 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);
    }
}

js string to boolean -

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

Convert string to boolean in javascript -

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

Comments

Submit
0 Comments