Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use substring () in JavaScript

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how to use substring () in JavaScript". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use substring () in JavaScript" can help you solve your doubts.

The jssubstring () method is used to extract characters that are mediated between two specified subscripts.

Jssubstring () syntax

StringObject.substring (start,stop)

Parameter description

Start is required. A non-negative integer that specifies the position of the first character of the substring to be extracted in the stringObject.

Stop

Optional. A non-negative integer that is 1 more positioned in stringObject than the last character of the substring to be extracted.

If this parameter is omitted, the substring returned will go all the way to the end of the string.

Return value

A new string whose value contains a substring of stringObject whose contents are all characters from start to stop-1, whose length is stop minus start.

Description

The substring returned by the substring () method includes the character at start, but not the character at stop.

If the parameter start is equal to stop, the method returns an empty string (that is, a string of length 0). If start is larger than stop, the method swaps these two parameters before extracting the substring.

Tips and comments

Important: unlike the slice () and substr () methods, substring () does not accept negative parameters.

Jssubstring () instance

Example 1

In this example, we will use substring () to extract some characters from the string:

Varstr= "Helloworld!"

[xss_clean] (str.substring (3))

Output:

Loworld!

Try it yourself.

Example 2

In this example, we will use substring () to extract some characters from the string:

Varstr= "Helloworld!"

[xss_clean] (str.substring (3. 7))

Output:

Low

After reading this, the article "how to use substring () in JavaScript" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report