八. 字符串模板函数

// .startsWidth()  //开头开始,第二个参数为所在位置javascript

// .endsWidth()  //结尾开始, 第二个参数为所在位置java

// .includes()3d

// .repeat()blog

 

  示例:ip

  

const id = '51030019800730366'

const fan = 'I Love WangRong'

1. startsWidth()

id.startsWidth('51')            //true
id.startsWidth('1980',6)      //true

  

2.endsWidth()

id.endsWidth('x')            //true
fan.endsWidth('Love',6)    // true    Love最后一个字母所在的位置

  

3.includes()  字符串中是否包含某个字符

fan.includes('WangRong')    //true
fan.includes('WangRong',10)    //false
//Es5写法 fan.indexOf('WangRong') !== -1 //true

  

4.repeat()  //重复次数,能够美化字符串

const heading = `${'='.repeat(5)}${fan}${'='.repeat(5)}`

 

 

可实现对齐方式:字符串

例如:class

  

相关文章
相关标签/搜索