欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ES6知識(shí)點(diǎn)整理之String字符串新增常用方法示例

 更新時(shí)間:2019年07月23日 11:45:46   作者:Johnny丶me  
這篇文章主要介紹了ES6知識(shí)點(diǎn)整理之String字符串新增常用方法,結(jié)合實(shí)例形式分析了ES6字符串String includes,startsWith,endsWith等方法相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了ES6知識(shí)點(diǎn)整理之String字符串新增常用方法。分享給大家供大家參考,具體如下:

字符串includes,startsWith,endsWith方法測(cè)試

普通的用法:

<script>
var str = 'Hello';
console.log(str.indexOf('o')); // 4
console.log(str.includes('e')); // true
console.log(str.startsWith('H')); // true
console.log(str.endsWith('e')); // false
</script>

運(yùn)行結(jié)果:

添加第二個(gè)參數(shù)之后,標(biāo)注查詢的起始位置:

<script>
var str = 'Hello';
console.log(str.includes('e',1)); // true
console.log(str.startsWith('e',1)); // true
console.log(str.endsWith('l',3)); // true
</script>

運(yùn)行結(jié)果:

實(shí)用的repeat方法

<script>
var str = 'Hello';
var res = str.repeat(3);
console.log(res); // HelloHelloHello
</script>

運(yùn)行結(jié)果:

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。

String 中更多的API【官方文檔】用時(shí)可查詢

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

更多關(guān)于JavaScript相關(guān)內(nèi)容可查看本站專(zhuān)題:《javascript面向?qū)ο笕腴T(mén)教程》、《JavaScript查找算法技巧總結(jié)》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)

希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論