es5
var arr1=["上海","北京","广州"]; var arr2=[12,22, 33,58,32,45,92]; // 数组.方法(function (item, index) {}) // 1. forEach 等价 for arr1.forEach(function(item,index){ console.log(item,index); //上海 北京 广州 //0 1 2 }); // 2. map 映射 var arrMap=arr2.map(function(item,index){ return item *2; }) console.log(arrMap,"map");//[24, 44, 66, 116, 64, 90, 184] "map" //3.filter 过渡 var arrFilter=arr2.filter(function(item,index){ return item >50; }); console.log(arrFilter,"arrFilter");//(2) [58, 92] "arrFilter" //4.every 每一个的意思 他会返回ture或者false //所有的条件全部满足就返回ture否则返回false var flagEvery=arr2.every(function(item,index){ return item > 30; }) console.log(flagEvery,"every"); //5.some 每一个的意思 他会返回ture或者false //只要有一个条件满足就返回ture否则返回false var flagSome=arr2.some(function(item,inde){ return item>30; }) console.log(flagSome,"some");
Sometimes you need to applaud yourself