Blogger Information
Blog 12
fans 0
comment 0
visits 8880
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2020-05-30——ES6 遍历字符串
A 枕上人如玉、
Original
872 people have browsed it

使用for…of代替for循环:

  1. var string = 'string'
  2. for(var i of string) {
  3. console.log(i)
  4. }

includes(),startsWidth(),endsWidth()
不用使用indexOf()判断字符串中是否包含某个值了,使用includes():

  1. var string = 'string'
  2. string.includes('i' 0) // true

includes第二个参数表示查找的起始索引。还可以使用startsWidth()和endsWidth()判断字符串是否以某些字符开始或结尾。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post