slice()
类型化数组对象的方法从数组缓冲区(作为单独的对象)返回一部分或块。它接受两个整数参数,分别表示要返回的数组部分的开始和结束。
它的语法如下
arrayBuffer.slice(3, 8)
<html> <head> <title>JavaScript Array every Method</title> </head> <body> <script type="text/javascript"> var typedArray = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]); document.write("Contents of the typed array: "+typedArray); document.write("<br>"); var resultantArray = typedArray.slice(2, 7); document.write("Resultant Array: "+resultantArray); </script> </body> </html>
输出结果
Contents of the typed array: 11,5,13,4,15,3,17,2,19,8 ResultantArray: 13,4,15,3,1