1.如果您希望把单词分割为字母,或者把字符串分割为字符,可使用下面的代码:
var words = sentence.split(' ')
2.如果您希望把单词分割为字母,或者把字符串分割为字符,可使用下面的代码:
"hello".split("") //可返回 ["h", "e", "l", "l", "o"]
3.若只需要返回一部分字符,请使用 howmany 参数:
"hello".split("", 3) //可返回 ["h", "e", "l"]
4.或者使用正则表达式作为 separator:
var words = sentence.split(/\s+/)