基本概念3-字符串

2022-01-27  本文已影响0人  娇娇_5038

     let text='吉祥如意';

     console.log(text.length)

     console.log(text.charAt(0))//查找第几个字符

     console.log(text.charCodeAt(0))//返回一个字符的Unicode的编码

     console.log(text.codePointAt(0))//返回的一个字符串Unicode的编码

     console.log(text.normalize())

     let msg="Hello world!";

     //startsWith,endsWith,includes 只有一个参数的时候书按整个字符串去匹配,第二个参数是从第几个字符开始匹配

     console.log(msg.startsWith('Hello',5));//刚开始的位置是否有这个字符串 FALSE

     console.log(msg.endsWith('!'));//这个字符串是否含有叹号

     console.log(msg.includes('o'));//这个字符串是否包含o

     console.log(msg.indexOf('o'));//注 方法对大小写敏感,如果搜索的字符串未出现则返回-1,如果出现可返回某个指定的字符串值在字符串中首次出现的位置

     console.log(msg.lastIndexOf('o'));//如果搜索的字符串未出现则返回-1,如果出现可返回某个指定的字符串值在字符串中最后一次出现的位置

      console.log('x'.repeat(3));//xxx 只接受一个number类型的参数,表示该字符串重复的次数

上一篇 下一篇

猜你喜欢

热点阅读