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

Introduction to 2 functions for intercepting strings in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:38:371282browse

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.

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