被遗忘的javascript的slice() 方法_javascript技巧

WBOY
Release: 2016-05-16 16:03:04
Original
1133 people have browsed it

slice() 方法可从已有的数组中返回选定的元素。

好吧,我承认我竟然把它忘了!

这次我在回顾一下它

语法

arrayObject.slice(start,end)
数组.slice(起始,结束)

Copy after login

Thomas,James

选取数组索引第2到4

实例代码:

实例一:
代码如下:

var a="abcdefgmnlxyz"; console.log(a.slice(2,3));
Copy after login

截取位置“2”到位置“3”之间的字符串,但是位置“3”对应的字符d不在截取返回之内。输出结果:c。

实例二:
代码如下:

var a="abcdefgmnlxyz"; console.log(a.slice(2));
Copy after login

如果第二个参数省略,那么将截取从位置“2”到字符串结尾的所有字符。输出结果:cdefgmnlxyz。

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!