JS(四)——对象,字符串对象

126 阅读1分钟

获取对象下属性的方法

    var tmp = 'name';
    console.log(p1.name);
    console.log(p1['name']);
    console.log(p1[tmp]);

字符串对象

  1. replace("world","Aiors") 把world替换成Aiors
  2. split 把字符串转换成数组
  3. indexof检索字符串中某个字符首次出现的位置,如果没有返回-1
  4. lastindexof 检索字符串中某个字符最后一次出现的位置
  5. substr(index,length)从index开始,截取length长度的字符串
  6. substring(start,end) 不包含end的截取与slice相同
  7. charAt(0)指定字符串位置