1、使用 split() 方法:
let str = "Hello, World!";
let arr = str.split(" "); // ["Hello,", "World!"]
2、使用扩展运算符(…)和 split() 方法:
let str = "Hello, World!";
let arr = [...str.split(" ")]; // ["Hello,", "World!"]
3、使用 Array.from() 方法:
let str = "Hello, World!";
let arr = Array.from(str, function(char) { return char; });
// ["H", "e", "l", "l", "o", ",", " ", "W", "o", "r", "l", "d", "!"]
4、数组转字符串
const array = ['apple', 'banana', 'orange'];
const string = array.join(', '); // 使用逗号和空格作为分隔符
console.log(string); // 输出 "apple, banana, orange"