八. 字符串模板函数

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

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

// .includes()

// .repeat()

 

  示例:

  

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)}`

 

 

可实现对齐方式:

例如:

  

 

 

  

posted @ 2019-10-30 16:41  小蓉儿  阅读(183)  评论(0编辑  收藏  举报