Home  >  Article  >  Web Front-end  >  Getting started with the slice method of JavaScript string objects (for string interception)_Basic knowledge

Getting started with the slice method of JavaScript string objects (for string interception)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:33:391139browse

JavaScript slice method

The slice method is used to intercept a part of a string and return that part of the string. Its syntax is as follows:

Copy code The code is as follows:

str_object.replace(start, end)

Parameter description:

参数 说明
str_object 要操作的字符串(对象)
start 必需。要截取的开始位置,从 0 开始计算;如果为负数,则从字符串末尾反向开始计算
end 可选。要截取的结束位置,如果省略则到字符串结束;如果为负数,则从字符串末尾反向开始计算

slice method instance

Copy code The code is as follows:


Run this example, output:

Copy code The code is as follows:

bcdef
bc
ef
cd
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