Liaoche JS Tutorial Learn to record---string

Source: Internet
Author: User

1. Since multiline strings are more \n cumbersome to write, the newest ES6 standard adds a multi-line string representation, using ' ... '`这是一个

多行字符串`;

2.字符串常见的操作如下:
// 13

要获取字符串某个指定位置的字符,使用类似Array的下标操作,索引号从0开始:
s[12]; // ‘!‘s[13]; // undefined 超出范围的索引不会报错,但一律返回undefined

3. It is important to note that the string is immutable, and there is no error if you assign a value to an index of the string, but it does not have any effect:

var s = ‘Test‘;s[0] = ‘X‘;alert(s); // s仍然为‘Test‘

4.JavaScript provides some common methods for strings, note that calling these methods does not alter the contents of the original string, but instead returns a new string:

toUpperCase (): Turns a string into uppercase toLowerCase: turns a string all lowercase indexOf: searches for the starting position where the specified string appears, and cannot find the return to-1SUBSTRING: Returns the substring of the specified index interval:
var s = ‘hello, world‘s.substring(0, 5); // 从索引0开始到5(不包括5),返回‘hello‘s.substring(7); // 从索引7开始到结束,返回‘world‘
 

Liaoche JS Tutorial Learn to record---string

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.