首頁  >  文章  >  web前端  >  ES6的字串模板詳解

ES6的字串模板詳解

php中世界最好的语言
php中世界最好的语言原創
2018-03-10 14:19:411926瀏覽

這次帶給大家ES6的字串模板詳解,使用ES6的字串模板的注意事項有哪些,下面就是實戰案例,一起來看一下。

    //ES5方式:
    var text = "沧海";
    var whole = "蝴蝶再美,终究飞不过" + text;
    //ES6方式; 并且支持字符串的查找(支持中文),运算;
    var name = "lovely_sr";
    var whole1 = `I love ${name} <br> <b>so much</b><br>`;
    //{}中放表达式;
    var c = 2;
    var d = -3;
    console.log(whole);
    document.write(whole1);
    document.write(whole1.repeat(10));
    document.write("呵呵");
    console.log(whole1.indexOf(name) > 0);
    console.log(whole1.includes(name));
    console.log(whole1.startsWith(name));
    console.log(whole1.endsWith(name));
    console.log(`${c+d}`);
    console.log(`${c}${d}`);

我相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

相關閱讀:

ES6的拓展運算子詳解

ES6的變數的作用域與宣告詳解

以上是ES6的字串模板詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn