The method used in JS

Source: Internet
Author: User

In Learning JS Foundation, sometimes learn to forget, write down to facilitate the next search and understanding:

The. Substring () method is used to extract the character of a string intermediary between two specified subscripts.

var str='abcdef'; alert (str.substring (25));    // starting from 2nd position (including 2 brothers) to 4th end (excluding 5th) pop-up CDE // Alert (str.substring (1)); // starting from 1th to last pop-up bcdef

The. CharAt () method returns the character at the specified position

var str='abcdef'; alert (Str.charat (0));//Output is a

The. Search () method is used to retrieve a substring specified in a string, or to retrieve a substring that matches a regular expression

var str='abcdef'; alert (Str.search ('b') ));      // Output 1 position, 1alert (str.search ('u'));        // location,-1

The. Split () method is used to split a string into a string array.

var str='12-56-aaa-89'; var arr=str.split ('-'// output 12,56,aaa,89

The. Replace () method is used to replace other characters with some characters in a string, or to replace a substring that matches a regular expression.

var str='ABC aaa ERW'; var re=/a/'0');//Replace all a with 0

The. Match () method retrieves the specified value within a string, or finds a match for one or more regular expressions.

var str='asdf 656 cvs33'; var re=/\d/G;alert (Str.match (re)); // Output 3,4,6,5,6,3,3 // var str= "Hello world!" //  // World

The method used in JS

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: info-contact@alibabacloud.com 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.