ES6新增常用的属性

1,includes
String.includes(x,i)//查询一个字符串中是否包含另一个字符串 x表示子字符串 i表示查询的起始位置 返回布尔值

string.indexof(x)返回查询的位置

'zhangyachao'.includes('a',0)//true

'zhangyachao'.includes('a',11)//false

'zhangyachao'.indexOf('yachao')//5

'zhangyachao'.indexOf('a')//2

2,forEach(数组的循环不能中断)

array.forEach(function(currentValue,index,array){}) 

//必须 currentValue:当前的元素

//可选参数        index:当前元素的索引值

//可选参数        array  :当前元素所属的数组对象

例子: [2,3,4,5,6,7,8,9].forEach((value,index,arr)=>{console.log(value,index,arr)})  

//2 0  [2, 3, 4, 5, 6, 7, 8, 9]
 // 1  [2, 3, 4, 5, 6, 7, 8, 9]
// 4 2  [2, 3, 4, 5, 6, 7, 8, 9]
// 5 3  [2, 3, 4, 5, 6, 7, 8, 9]
// 6 4  [2, 3, 4, 5, 6, 7, 8, 9]
//7 5  [2, 3, 4, 5, 6, 7, 8, 9]
// 8 6  [2, 3, 4, 5, 6, 7, 8, 9]
// 9 7  [2, 3, 4, 5, 6, 7, 8, 9]       

你可能感兴趣的:(常用属性)