要将JavaScript中的布尔值转换为字符串值,请使用toString()
方法。此方法根据对象的值返回字符串“ true”或“ false”。
您可以尝试运行以下代码将布尔值转换为字符串值-
<html> <head> <title>JavaScript toString() Method</title> </head> <body> <script> var flag = new Boolean(true); document.write( "flag.toString is : " + flag.toString() ); </script> </body> </html>