Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of substring method in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 03:06:16 10月04日 Update

This article mainly introduces what is the use of the substring method in JavaScript, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The substring method returns the substring at the specified location in the String object.

StrObj.substring (start,end)

Description:

Start indicates the starting position of the substring, with the index starting at 0.

End indicates the end of the substring, with the index starting at 0.

The substring method uses the smaller of both start and end as the starting point for the substring. If start or end is NaN or negative, replace it with 0.

For example:

012345

Var str = "ABCDEF"

Str.substring (2pr 4); / / or str.substring (4pr 2)

Results: CD

Thank you for reading this article carefully. I hope the article "what is the use of substring in JavaScript" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Method character string article location Akiko index start middle finger value interest at the same time object more friend knowledge result ribbon industry negative number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi NVidia Xiaomi MariaDB