Review of the day before JS

Source: Internet
Author: User

1.method of the string object (1)--Case Conversion

var str1= "ABCD"

var str2=str1.tolowercase ();//"ABCD"

var str2=str1.touppercase ();//"ABCD" var str1= "Welcome to the world of js!";

2.method of String Object (2)--Retrieval of characters

var str1= "Welcome to the world of js!";

var str2=str1.indexof ("L");//starting from 0, the result is 2;

var str3=str1.lastindexof ("L"), starting from 0, with a result of 18;

var str2 = Str 1 . Match ("World");//used to find the string

var Str 3 = Str 1 . Match ("World");//The first character position index used to match a string

Alert (str2[0]); //Results are " World " ;

alert (STR3);//The result is 15;

Method of 3.String Object (3)--substring processing

Calculate substring length

var str1= "ABcd EFGHJ "

Console.log (str1.length);//Calculation length

Console.log ( substr (str1. (1,4));//x.substr (start, length) results "Bcde"

Console.log ( substring (str1. (1,4));//x.substr (start, end) result "Bc"

var str2=str1.slice (2,4);

var str3=str1.slice (4);

var str4=str1.slice (2,-1);

var str5=str1.slice ( -3,-1);

alert (STR2);

The result is "CD"

alert (STR3);

The result is "EFGH"

alert (STR4);

The result is "CDEFG"

alert (STR5);

The result is "FG"

Review of the day before 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.