1stringToBoolean: function(string){
2 switch(string.toLowerCase().trim()){
3 case "true": case "yes": case "1": return true;
4 case "false": case "no": case "0": case null: return false;
5 default: return Boolean(string);
6 }
7}
1function parseBool(value) {
2 if (typeof value === "string") {
3 value = value.toLowerCase();
4 if (value === "true" || value === "false") {
5 return value === "true";
6 }
7 }
8 return; // returns undefined
9}
1const stringBools = [
2 'true',
3 'false',
4 'asdf'
5];
6const bools = [];
7
8for (const i = 0; i < stringBools.length; i++) {
9 const stringBool = stringBools[i];
10 if (stringBool == true) {
11 bools.push(true);
12 } else if (stringBool == false) {
13 bools.push(false);
14 } else {
15 bools.push(null /* Change if you like */);
16 }
17}