此方法通过将字符串拆分成子字符串,将String对象拆分为字符串数组。
string.split([separator][, limit]);
separator - 指定用于分隔字符串的字符。
limit - 整数指定要找到的拆分数的限制。
Split方法返回新数组。此外,当字符串为空时,Split返回包含一个空字符串的数组,而不是空数组。
<html> <head> <title>JavaScript String split() Method</title> </head> <body> <script type="text/javascript"> var str="Apples are round, and apples are juicy."; var splitted=str.split(" ", 3); document.write( splitted ); </script> </body> </html>
运行上面代码输出
Apples,are,round,
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)