Home > Web Front-end > JS Tutorial > Introduction to 2 functions for intercepting strings in JavaScript_javascript skills

Introduction to 2 functions for intercepting strings in JavaScript_javascript skills

WBOY
Release: 2016-05-16 16:38:37
Original
1299 people have browsed it

First, let’s take a look at the introduction to the use of the substring function.

1. substring

substring requires at least one parameter, the first parameter is the starting position, and the second optional parameter is the ending position.

Only one parameter:

Copy code The code is as follows:




Two parameters:
Copy code The code is as follows:



2. substr

substr also requires at least one parameter. The first parameter is the starting position, and the second parameter is optional and is the length.

Only one parameter:

Copy code The code is as follows:




Two parameters:
Copy code The code is as follows:



As can be seen from the above example, when substring and substr have only one parameter, the results are the same, and only the second parameter is different.

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