有多种方法可以将字符串分割成字符数组,我更喜欢使用扩展操作符(...):
<!DOCTYPE HTML> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <style> </style> </head> <body> </body> <script type="text/javascript"> const a = 'wangting' const characters = [...a] console.log(characters) // ["w", "a", "n", "g", "t", "i", "n", "g"] </script> </html>