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");