Home > Web Front-end > JS Tutorial > body text

Getting started with the substr method of JavaScript string objects (used to intercept strings)_Basic knowledge

WBOY
Release: 2016-05-16 16:33:34
Original
1270 people have browsed it

JavaScript substr method

The

substr method is used to intercept a string based on the starting position and length and return the intercepted part of the string. Its syntax is as follows:

Copy code The code is as follows:

str_object.substr(start, length)

Parameter description:

参数 说明
str_object 要操作的字符串(对象)
start 必需。开始截取的位置,从 0 开始计算;如果为负数则从字符串末尾开始计算(经测试,某些浏览器版本下无效)
length 可选。指要截取的字符串长度,省略则至到字符串结束

Tip: The substr method does not comply with the ECMAscript standard and is therefore not recommended.

substr method instance

Copy code The code is as follows:


Run this example, output: jb51

Copy code The code is as follows:

jb51
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template