這篇文章主要講解了“ES6字符串實(shí)例分析”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“ES6字符串實(shí)例分析”吧!

1、多了兩個(gè)新方法
(1)startWith:判斷一個(gè)字符串是否以某個(gè)字段開(kāi)頭
let str='asdfgh';console.log(str.startsWith('a'));//true應(yīng)用:
let str='http://it.kaikeba.com';if(str.startsWith('http://')){ console.log("普通網(wǎng)址")}else if(str.startsWith('https://')){ console.log("加密網(wǎng)址")}else if(str.startsWith('git://')){ console.log("git網(wǎng)址")}else if(str.startsWith('svn://')){ console.log("svn網(wǎng)址")}else{ console.log("其他網(wǎng)址")}(2)endsWith:判斷一個(gè)字符串是否以某個(gè)字段結(jié)尾
同理:
let str='asdfg.txt';if(str.endsWith('.txt')){ console.log("文本文件")}else if(str.endsWith('.png')){ console.log("png圖片")}else if(str.endsWith('.jpg')){ console.log("jpg圖片")}else{ console.log("其他文件")}2、字符串模板,字符串連接
(1)直接把東西塞到字符串中
let str1='asdfgh';//第一種字符串方式let str2='asdfgh';//第二種字符串方式let str3=`asdfgh`;//第三種:反單引號(hào)/應(yīng)用:let a=12;let str4=`a${a}bc`;console.log(str4);//a12bc(2)可以折行
let title='標(biāo)題';let content='內(nèi)容';let str1='<div>\ <h2>'+title+'</h2>\ <p>'+content+'</p>\</div>'; let str2=` <div> <h2>${title}</h2> <p>${content}</p> </div> `;感謝各位的閱讀,以上就是“ES6字符串實(shí)例分析”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)ES6字符串實(shí)例分析這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
標(biāo)題名稱:ES6字符串實(shí)例分析-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)路徑:http://chinadenli.net/article20/dsjjjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、商城網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、域名注冊(cè)、定制開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容