1.遍历器接口

    1. for (let codePoint of 'foo') {
    2. console.log(codePoint)
    3. }
    4. // "f"
    5. // "o"
    6. // "o"

    2.字符串模板语法

    1. $('#test').append(`
    2. There are <b>${basket.count}</b> items
    3. in your basket, <em>${basket.onSale}</em>
    4. are on sale!
    5. `);

    3.传统上,JavaScript 只有indexOf方法,可以用来确定一个字符串是否包含在另一个字符串中。ES6 又提供了三种新方法。

    • includes():返回布尔值,表示是否找到了参数字符串。
    • startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
    • endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
      1. let s = 'Hello world!';
      2. s.startsWith('Hello') // true
      3. s.endsWith('!') // true
      4. s.includes('o') // true
      这三个方法都支持第二个参数,表示开始搜索的位置。
      1. let s = 'Hello world!';
      2. s.startsWith('world', 6) // true
      3. s.endsWith('Hello', 5) // true
      4. s.includes('Hello', 6) // false
      上面代码表示,使用第二个参数n时,endsWith的行为与其他两个方法有所不同。它针对前n个字符,而其他两个方法针对从第n个位置直到字符串结束。

    参考http://es6.ruanyifeng.com/#docs/string-methods#%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95%EF%BC%9Aincludes-startsWith-endsWith