ES6新增对数组/字符串操作方法
2018-06-27 本文已影响0人
三寸日光_
一,字符串相关
1.includes(): 返回布尔值,表示是否找到了参数字符串
2.startsWith(): 返回布尔值,表示参数字符串是否在原字符串头部
3.endsWidth(): 返回布尔值,表示参数字符串是否在原字符串尾部
以上都接受第二个参数,表示开始搜索的位置

4.repeat() : 返回一个新的字符串,表示将原字符串重复n次。

5.padStart(),padEnd(); :如果字符串不够指定长度,会在头部或尾部补全。接受两个参数,第一个参数用来指定字符串最小长度,第二个参数是用来补全的 字符串,不写第二个参数,默认用空格补全。

6.map 和 reduce map是对数组内每个成员进行一样的操作,比如把数组内每个元素扩大两倍;reduce是对数组内所有元素进行操作,比如实现数组内元素求和。


二、数组操作
1.遍历数组 forEach

2.映射新数组 map 返回新数组

3.所有元素是否测试通过 every 返回布尔值

4.是否有元素测试通过 some 返回布尔值

5.过滤数组 filter 返回新数组

6.查找符合条件的元素
7.查找索引 indexOf 返回第一次出现的位置索引值

8.连接数组 ‘...’扩展运算符

9.数组去重 new Set()
