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