Home  >  Article  >  Web Front-end  >  js中slice()方法的使用说明_基础知识

js中slice()方法的使用说明_基础知识

WBOY
WBOYOriginal
2016-05-16 19:17:131552browse

该Javascript示例解释:这个示例用到了数组(Array)对象的Slice(start,[end])方法,该方法返回一个新数组,包含了源函数从start到 end 所指定的元素,但是不包括end元素,比如a.slice(0,3);如果 start 为负,将它作为 length + start处理,此处 length 为数组的长度,比如a.slice(-3,4),相当于a.slice(2,4)。如果 end 为负,就将它作为 length + end 处理,此处 length 为数组的长度,比如a.slice(0,-1)。如果省略 end ,那么 slice 方法将一直复制到源数组结尾,比如a.slice(1)。如果 end 出现在 start 之前,不复制任何元素到新数组中,比如a.slice(4,3)。


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn