es6字符串拓展

  1. 字符串可以直接遍历啦

    for(let codepoint of 'foo'){
        console.log(codepoint); // f,o,o
    }
    
  2. includes(), startsWidth(), endsWidth()

    const s='hello world';
    s.startWidth('hello') // true
    s.endsWidth('d') // true
    s.includes('o')  // true
    s.includes('1')  // false
    
  3. repeat

    'x'.repeat(3) // xxx
    
  4. 模板字符串

    let name="bob", time ="today";
    console.log(`hello ${name}, how are you${time}`)
    
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容