js 字符串

1、split(separator,limit)字符串分割成字符串数组

  • separator可选,从该参数指定的地方分隔
  • limit可选,返回数组的长度
var str = "How are you";
var a = str.split();  //["How are you"]
var b = str.split("");  //["H", "o", "w", " ", "a", "r", "e", " ", "y", "o", "u"]
var c = str.split(" ");  //["How", "are", "you"]
var d = str.split(" ",2);  //["How", "are"]

参考:

https://www.runoob.com/jsref/jsref-obj-string.html

你可能感兴趣的:(js 字符串)