7.3、String对象--字符串对象
String对象中提供的方法都是处理字符串。
用法一:
var s = new String(要处理的字符串); //实例化对象
console.log(s.substr(1)); //对象通过点语法调用String对象的成员方法
用法二:把字符串直接当做对象来使用
console.log(要处理的字符串.substr(1));
//用法一
var s = new String('hello world');console.log(s.length); //表示字符串长度
console.log(s.indexOf('a')); // 没有查到,返回-1
console.log(s.indexOf('l')); //查到了,返回位置 2//用法二:直接把字符串当做字符串对象来使用
console.log('hello world'.indexOf('e')); // 1
console.log('abcdefg'.substr(2, 3)); // cde