javascript字符串对象(方法,属性)

属性

  • constructor:构造函数 。
  • __proto__:指向构造函数的原型对象 。
  • length:字符串长度 。

方法

查找
  • carharAt(i):返回指定位置对应的字符 。
    let a = [1,2,8,4,5,6,0,8]
    let b = a.toString()
    let c = b.charAt(2)
    console.log( c )
    
  • charCodeAt(i):返回指定位置字符对应的ASCLL码值 。
    let a = [1,2,8,4,5,6,0,8]
    let b = a.toString()
    let c = b.charCodeAt(2)
    console.log( c )
    
  • string.fromCharCode(50):将ASCLL码值转化为字符 。
    let a = String.fromCharCode(50)
    console.log(a);
    
  • indexOf(str1):返回指定字符 str1 在字符串中首次出现的位置
    let a = '1,2,8,4,5,6,2,8'
    let b = a.indexOf('2')
    console.log(b);
    
  • lastIndexOf(str1):返回指定字符在字符串中最后一次出现的位置,否则返回 -1 。
    let a = '1,2,8,4,5,6,2,8'
    let b = a.lastIndexOf('8')
    console.log(b);
    
  • includes(str1):判断字符串中是否包含str1,若包含返回true,否则返回false 。
    let a = '1,2,8,4,5,6,2,8'
    let b = a.includes('9')
    console.log(b);
    
替换
  • replace(str1,str2):用str2替换str1在字符串中首次出现的位置,不影响原字符串 。
    let a = '1,2,8,4,5,6,2,8'
    let b = a.replace(2,9)
    console.log(b);
    console.log(a);
    
重复
  • repeat(num):字符串重复出现num次 。
    let a = '1,2,8,4,5,6,2,8'
    let b = a.repeat(2)
    console.log(b);
    console.log(a);
    
转换
  • str.toUpperCase():转换为大写 。
    let a = 'a,b,c,d,e,f,8'
    let b = a.toUpperCase()
    console.log(b)
    
  • sre.toLowerCase():转换为小写 。
    let a = 'E,D,C,G,U,I,8'
    let b = a.toLowerCase()
    console.log(b)
    
  • split():按照指定的标识符,将字符串转换为数组 。
    let a = 'E,D,C,G,U,I,8'
    let b = a.split()
    console.log(b)
    
截取
  • slice(start,end):截取从 startend ,但是不包括 end 位置字符,不影响原字符串 。
    let a = 'E,D,C,G,U,I,8'
    let b = a.slice(1,5)
    console.log(b)
    console.log(a)
    
  • substring(start,end):不支持负数
    	let a = 'E,D,C,G,U,I,8'
    	let b = a.substring(1,5)
    	console.log(b)
    	console.log(a)
    
  • substr(start,length):从 start 开始截取指定长度 。
    let a = 'E,D,C,G,U,I,8'
    let b = a.substr(1,5)
    console.log(b)
    console.log(a)
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值