Array.prototype.slice() 方法
来源:互联网 发布:淘宝招聘中老年女模特 编辑:程序博客网 时间:2024/06/06 01:00
MDN 链接: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
W3C 链接: http://www.w3school.com.cn/jsref/jsref_slice_array.asp
定义和用法
slice() 方法可从已有的数组中返回选定的元素。
语法
arrayObject.slice(start,end)
参数
返回值
返回一个新的数组,不改变原来的数组,包含从 start 到 end (不包括该元素)的 arrayObject 中的元素。
说明
请注意,该方法并不会修改数组,而是返回一个子数组。如果想删除数组中的一段元素,应该使用方法 Array.splice()。
代码:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Array.prototype.slice()</title></head><body><script> // slice:切片 var array = [0, 1, 2, 3, 4, 5, 6, 7, 8]; // 输出原始数组 console.log(array); // 从下标1开始选取 console.log(array.slice(1)); // 从最后一个开始选取 console.log(array.slice(-1)); // 从下标2选取,下标3结束; 输出的数组不包含后一位 console.log(array.slice(2, 3)); // 从倒数第5位开始,在倒数第1位结束,不包括倒数第一位 console.log(array.slice(-5, -1)); // 再次输出原始数组 console.log(array);</script></body></html>
运行结果:
0 0
- Array.prototype.slice() 方法
- Array.prototype.slice.call()方法详解
- Array.prototype.slice.call()方法详解
- Array.prototype.slice.call()方法详解
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice 妙用
- js利用prototype调用Array的slice方法
- Array.prototype.slice.call()详解及转换数组的方法
- Array.prototype.slice.call()详解及转换数组的方法
- Array.prototype.slice.call()详解及转换数组的方法
- 什么是Array.prototype.slice.call
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- TSubclassOf<> 和 FStringClassReference 在类成员中的作用
- 路由器的中继模式Repeater和桥接模式Bridge有什么区别
- poj 2114 Boatherds (点分治)
- 在浏览器中,按f5(浏览器中的刷新按钮),与f5+ctrl 、回车的区别
- 圣墟 > 第一百二十九章 异类直播
- Array.prototype.slice() 方法
- cacti安装与配置
- Error:(1, 0) Your project path contains non-ASCII characters. This will most likely
- windows7 下安装python2.7 setuptools pip
- Gson 中文指南
- String.prototype.slice() 方法
- nodejs+好雨云平台git免费搭建个人博客
- HTML每日一结1.12
- 状态流程控制