JavaScript函数
来源:互联网 发布:c语言log函数怎么调用 编辑:程序博客网 时间:2024/05/17 02:39
slice()方法可将现存数组中的选中元素返回
arrayObject.slice(start,end)
start: Required. Specify where to start the selection. Must be a number
必要选项。指定开始的位置。必须是数字
end: Optional. Specify where to end the selection. Must be a number
可选项。指定结束的位置。必须是数字
Tip: You can use negative index numbers to select from the end of the string.
提示:你可以用一个负的起始值从字符串的末尾开始选取字符
Note: If end is not specified, slice() selects all characters from the specified start position and to the end of the string.
注意:如果没有指定结束的位置,slice()将选取从指定起始位置开始到字符串结束的所有字符
实例1
In this example we will extract all characters from a string, starting at position 6:
在本例中,我们将选取字符串中第6个字符以后的所有字符:
<script type="text/javascript">
var str="Hello happy world!"
document.write(str.slice(6))
</script>
The output of the code above will be:
输出结果为:
happy world!
实例2
In this example we will extract all the characters from position 6 to position 11:
在本例中,我们将从字符串中选取第6个字符到第11个字符间的字符:
<script type="text/javascript">
var str="Hello happy world!"
document.write(str.slice(6,11))
</script>
The output of the code above will be:
输出结果为:
happy
实例3
In this example we will create an array, and then display selected elements from it:
在这个举例中我们将建立一个数组。并且选择性的显示其中的一部分元素:
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "Jani"
arr[1] = "Hege"
arr[2] = "Stale"
document.write(arr + "<br />")
document.write(arr.slice(1) + "<br />")
document.write(arr)
</script>
The output of the code above will be:
上面代码的输出结果为:
Jani,Hege,Stale
Hege,Stale
Jani,Hege,Stale
实例4
在这个举例中我们将建立一个数组,并将选中的元素显示出来:
<script type="text/javascript">
var arr = new Array(6)
arr[0] = "Jani"
arr[1] = "Hege"
arr[2] = "Stale"
arr[3] = "Kai Jim"
arr[4] = "Borge"
arr[5] = "Tove"
document.write(arr + "<br />")
document.write(arr.slice(2,4) + "<br />")
document.write(arr)
</script>
The output of the code above will be:
上面代码输出的结果为:
Jani,Hege,Stale,Kai Jim,Borge,Tove
Stale,Kai Jim
Jani,Hege,Stale,Kai Jim,Borge,Tove
- javascript函数
- Javascript函数
- Javascript函数
- javascript函数
- javascript函数
- javascript函数
- JavaScript函数
- JavaScript 函数
- JavaScript 函数
- JavaScript函数
- javascript函数
- javascript函数
- javascript函数
- JavaScript 函数
- javascript函数
- javascript 函数
- javascript函数
- javascript函数
- ubuntu下安装字体
- 关于“过劳死”的法律探讨
- netsh.exe简介
- MFC中 windows object 和 C++ object
- 我Blog中登上CSDN首页的文章
- JavaScript函数
- 百无一用是书生
- linux内核编译详解
- Quidway s3026简单组网案例+Quidway s2403简单组网案例
- java,存点临时东西,request的各get方法结果。
- 送给80年代后期出生的追梦人
- 设计模式之Factory
- RedHat Advance Server 3上安装oracle 9.2.0, 并升级到9.2.0.4
- 如何积累PDU