Home > Web Front-end > Front-end Q&A > How to use the javascript substring() method

How to use the javascript substring() method

青灯夜游
Release: 2022-03-08 18:15:27
Original
6378 people have browsed it

In JavaScript, the substring() method is used to extract the characters between two specified subscripts in the string. The syntax is "string.substring(from,to)"; the substring returned by this method includes The characters at the "from" parameter, but not including the characters at the "to" parameter.

How to use the javascript substring() method

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In JavaScript, the substring() method is used to extract characters between two specified subscripts in a string.

Syntax:

string.substring(from, to)
Copy after login
ParametersDescription
fromRequired. A nonnegative integer that specifies the position of the first character of the substring to be extracted in the string Object.
toOptional. A non-negative integer that is one more position in the string Object than the last character of the substring to be extracted.
If this parameter is omitted, the returned substring will go to the end of the string. The substring returned by the

substring() method includes the characters starting at from, but does not include the characters ending at to .

Example:

var str="Hello world!";
console.log(str.substring(3,7));
Copy after login

How to use the javascript substring() method

If the second parameter is omitted, it means to extract all characters from the starting position to the end.

var str="Hello world!";
console.log(str.substring(3));
Copy after login

How to use the javascript substring() method

[Related recommendations: javascript video tutorial, web front-end

The above is the detailed content of How to use the javascript substring() method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template