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 remove the first two bits of a string by javascript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to remove the first two characters of javascript string, Xiaobian think it is very practical, so share it for everyone to make a reference, I hope you can gain something after reading this article.

javascript to remove the first two digits of a string: 1, using the slice() function, syntax "string.slice(2)";2, using the substring() function, syntax "string.substring(2)".

Operating environment of this tutorial: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.

javascript Remove the first two digits of a string

Method 1: Use the slice() function

The slice(start, end) method extracts a portion of a string and returns the extracted portion as a new string.

Use the start (inclusive) and end (exclusive) parameters to specify the portion of the string extracted.

The first character position in the start parameter string is 0, the second character position is 1, and so on. If it is negative, it indicates how many strings are truncated from the tail. Slice(-2) indicates that the penultimate element in the original array is extracted to the last element (including the last element).

If the end parameter is negative,-1 refers to the position of the last character of the string,-2 refers to the penultimate character, and so on.

Examples:

var str="ab12345";console.log(str.slice(2)) // => 12345

Method 2: Use the substring() function

The substring(from, to) method is used to extract characters from a string between two specified subscripts.

The substring() method returns a substring that includes the characters at the beginning, but does not include the characters at the end.

Examples:

var str="ab12345";console.log(str.substring(2)) // => 12345

About "javascript how to remove the first two characters of the string" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

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

Development

Wechat

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

12
Report