1、Array.from():

这个函数的作用是将类似数组的对象转化为数组,比如DOM对象

let arrayLike = {
      "0":"TangSir",
      "1":28,
      "2":"nanjing",
      "3":"it",
      length:4
}

es5:console.log([].slice.call(arrayLike));   // ['TangSir',28,'nanjing','it']

es6:console.log(Array.from(arrayLike));   // ['TangSir',28,'nanjing','it']

2、Array.of():

与原来array的区别就是不管参数是多少个(大于0个)返回的都是统一的由参数组成的数组

let arr = [1,2,3];

console.log(Array.of(arr));   //[Array(3)]

3、find():

找出第一个符合该函数参数条件的数组成员,函数的参数是一个回调函数。是第一个符合,不是所有,也就是一旦找到一个符合的就return

console.log([1,2,-2,5].find((n)=>n<0)); //-2

let arr = [1,2,-2,5].find(function(value,index,arr){
return value < 0;
})

console.log(arr); //-2

4、findIndex():

与前面的find类似,但是返回的不是数组成员而是成员的索引,没有符合的返回-1,与find一样可以发现NaN这是在indexOf上的改进

console.log([1,2,-2,5].findIndex((n)=>n<0)); //2

let arr = [1,2,-2,5].findIndex(function(value,index,arr){
return value < 0;
})

console.log(arr); //2

5、includes():

返回布尔值,表示是否找到了参数/字符串

var str = 'hello word';  console.log(str.includes('he')) // 返回的结果是true

var arr = ['a','b','c','d']; console.log(arr.includes('a')) // 返回结果是true

var arr = ['a','b','c','d',NaN]; console.log(arr.includes(NaN)) //返回的记过是true  只要NAN存在,就会返回结果true,否则返回false

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2018-04-24
  • 2021-07-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-28
相关资源
相似解决方案