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