Summary of common methods for JavaScriptString objects _ javascript tips-js tutorial

Source: Internet
Author: User
The following is a summary of common methods for JavaScriptString objects. I think it is quite good. Now I want to share it with you. It is immutable to make a reference string for you. The string method does not change the content of the original string, but returns a new string.

CharAt (): returns the character at the specified position.

Concat (): concatenates two string texts and returns a new string.

IndexOf (): indexOf () method returns the position where the specified value first appears in a string object.

Match (): Use a regular expression to compare it with a string.

Replace (): Used to directly compare a regular expression with a string, and then replace the matched substring with a new substring.

Slice (): extract a string region and return a new string.

Split (): separates strings into strings and splits string objects into string arrays.

Substr (): returns the substring from the specified position to the specified length.

Substring (): returns the substring between two indexes (or to the end of the string.

Different from slice () and substr (), substring () does not accept negative parameters.

Trim (): removes spaces at both ends of a string.

The above is a summary of common methods for JavaScript String objects _ javascript tips. For more information, see PHP Chinese website ( )!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.