JavaScript数组方法

时间:2019-10-01 19:37:39   收藏:0   阅读:84

 

push

pop

shift

unshift

splice

slice

concat

toString

join

reverse

sort

indexOf / lastIndexOf

forEach遍历

可以用第二个参数改变第一个参数中的this

let ary=[12,23,34];
ary.forEach((item,index)=>{
...
});

map映射

let arr = [1, 2, 3, 4, 5]; 
let doubled = arr.map(num => {
 return num * 2;//把值放到新数组中
});

 

filter过滤

 let ary = [12, 23, 34, 25, 36, 47];
 ary = ary.filter((item, index) => {
      return item > 20 && item < 40;//=>返回的结果是TRUE或者FALSE,会把遍历后符合条件的放到新数组中
 });

 

find寻找

[12,23,34].find(item=>item>12);//23

 

 

原文:https://www.cnblogs.com/wangshouren/p/11615813.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!