Answers for "javascript boolean parse"

2

javascript parse string to boolean

let bool = "True";
JSON.parse(bool.toLowerCase());
Posted by: Guest on July-26-2021
3

string to 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;
    }
}
Posted by: Guest on November-25-2020
6

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);
    }
}
Posted by: Guest on May-05-2020
-1

js parse bool

function parseBool(value) {
    if (typeof value === "string") {
        value = value.toLowerCase();
        if (value === "true" || value === "false") {
            return value === "true";
        }
    }
    return; // returns undefined
}
Posted by: Guest on September-24-2021

Browse Popular Code Answers by Language