此方法提取字符串的一部分并返回一个新字符串。
string.slice( beginslice [, endSlice] );
beginSlice - 从零开始的索引。
endSlice - 结束索引。如果省略,则切片提取到字符串的末尾。
如果成功,Slice将返回字符串中正则表达式的索引。否则,返回-1。
<html> <head> <title>JavaScript String slice() Method</title> </head> <body> <script type="text/javascript"> var str="Apples are round, and apples are juicy."; var sliced=str.slice(3, -2); document.write( sliced ); </script> </body> </html>
运行上面代码输出
les are round, and apples are juic
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)