1其做、字符串截取
var str = "hello world";
var sub1 = str.substr(1, 3); // 第一個是開始位置囱挑, 第二個是長度 ell
var sub2 = str.substring(1, 3); // 第一個是開始位置菩彬,第二個是結(jié)束位置缠劝,長度為第二個-第一個 el
var sub3 = str.slice(1, 3); // 同上 允許負(fù)參
Paste_Image.png
2、長度計算,連接
var str = "hello";
console.log( str.length );
console.log( str[0] );
console.log( str[str.length - 1] );
console.log( str.charAt(0) );
console.log( str.charCodeAt(0) );
var str2 = " world";
var str3 = str + str2;
console.log( str3 );
Paste_Image.png
3骗灶、
Paste_Image.png
Paste_Image.png
Paste_Image.png
4. 大小寫
var str = "Hello";
str.toUpperCase();
str.toLowerCase();
Paste_Image.png
Paste_Image.png