var x ="JohnJohn"; // x 是字符串
y = x.charAt(2);// h
y = x.charCodeAt(2);// 104
y = x.concat(y, y);// JohnJohn104104, x+y+y
y = x.indexOf('h');// 2, 索引从0开始
y = x.lastIndexOf('h');// 6
y = x.slice();
y = x.split('o');//J,hnJ,hn
y = x.substr(2);// hnJohn
y = x.substring(2,4)// hn,[2,3]
y = x.toLocaleLowerCase();// johnjohn,小写
y = x.toLocaleUpperCase();// JOHNJOHN,大写
y = x.toString();// 转成Stirng
y = x.toUpperCase();// JOHNJOHN,大写
y = x.trim();// JohnJohn,去除两端的空格
y = x.valueOf();// 返回某个字符串对象的原始值
slice() 方法可提取字符串的某个部分,并以新的字符串返回被提取的部分。
语法:
stringObject.slice(start,end)
实例:
y = x.slice(2,5); // hnJ
y = x.slice(2); // hnJohn