In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.