如果想将一个字符串按空格分割成数组,可以使用JavaScript中的split()
方法。这个方法接受一个分隔符作为参数,并将字符串分割成多个子字符串,然后将这些子字符串存储在数组中。
const str = "Hello world, how are you today?";
const arr = str.split(" ");
console.log(arr); // ["Hello", "world,", "how", "are", "you", "today?"]
如果想将一个字符串按空格分割成数组,可以使用JavaScript中的split()
方法。这个方法接受一个分隔符作为参数,并将字符串分割成多个子字符串,然后将这些子字符串存储在数组中。
const str = "Hello world, how are you today?";
const arr = str.split(" ");
console.log(arr); // ["Hello", "world,", "how", "are", "you", "today?"]