js中的String对象
String对象提供的方法可以有两种调用方式
- 先实例化对象
var s = new String('Hello World');
console.log(s.length); // 11
console.log(s.indexOf('a')); // -1
- 直接将字符串当成对象使用
var s = 'Hello World';
console.log(s.length); // 11
console.log(s.indexOf('a')); // -1
转载必须注明出处:https://www.zhiqiexing.com/147.html