JAVASCRIPT convert string to boolean javascript - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

convert string to boolean javascript


 252

JAVASCRIPT


2

var str = "true";
var mybool = JSON.parse(str);

var parseBool = function(str)
{
// console.log(typeof str);
// strict: JSON.parse(str)

if(str == null)
return false;

if (typeof str === 'boolean')
{
return (str === true);
}

if(typeof str === 'string')
{
if(str == "")
return false;

str = str.replace(/^\s+|\s+$/g, '');
if(str.toLowerCase() == 'true' || str.toLowerCase() == 'yes')
return true;

str = str.replace(/,/g, '.');
str = str.replace(/^\s*\-\s*/g, '-');
}

// var isNum = string.match(/^[0-9]+$/) != null;
// var isNum = /^\d+$/.test(str);
if(!isNaN(str))
return (parseFloat(str) != 0);

return false;
}


By     Created   
The power of the user (%)
66%



The most helpful JAVASCRIPT solutions

How to get client machine name or computer name with javascript ?How to get client machine name or computer name with javascript ?JAVASCRIPT

Click to see more ...

  4.2K     374

get client hostname javascriptget client hostname javascriptJAVASCRIPT

Click to see more ...

  2.3K     254

detect ie javascriptdetect ie javascriptJAVASCRIPT

Click to see more ...

  1.5K     159

Create fireworks using javascriptCreate fireworks using javascriptJAVASCRIPT

Click to see more ...

  1.4K     113

create 3d barrel using javascriptcreate 3d barrel using javascriptJAVASCRIPT

Click to see more ...

  1.3K     83

get ip address javascriptget ip address javascriptJAVASCRIPT

Click to see more ...

  749     74

create qr code javascriptcreate qr code javascriptJAVASCRIPT

Click to see more ...

  511     71

how to create foreach class using javascript ?how to create foreach class using javascript ?JAVASCRIPT

Click to see more ...

  635     69

how to create the connect to a database with ADODB using javascript ?how to create the connect to a database with ADODB using javascript ?JAVASCRIPT

Click to see more ...

  453     59

get filename using javascript get filename using javascript JAVASCRIPT

Click to see more ...

  385     56