let arr = [{
? ? ? ? ? ? name: '戴森',
? ? ? ? ? ? price: 1000
? ? ? ? }, {
? ? ? ? ? ? name: '美的',
? ? ? ? ? ? price: 2000
? ? ? ? }, {
? ? ? ? ? ? name: '格力',
? ? ? ? ? ? price: 3000
? ? ? ? }]
1.find循環(huán),可以循環(huán)數(shù)組,找到第一個(gè)符合條件的一項(xiàng)就終止循環(huán),(原數(shù)組里面的成員)
let obj1 = arr.find(function (item, index) {
? ? ? ? ? ? return item.name=='格力'
? ? ? ? })
? ? ? ? console.log(obj1)
2.map循環(huán)
map可以把數(shù)組里面某一項(xiàng)組合成一個(gè)新數(shù)組? 對原數(shù)組不會(huì)造成改變
let arr2 = arr.map(function(item,index){
? ? ? ? ? ? console.log(item,index)
? ? ? ? ? ? return item.price
? ? ? ? })
? ? ? ? console.log(arr2,arr);
3.filter循環(huán)過濾
es6循環(huán)的過濾方法 回調(diào)函數(shù)里面 return 一個(gè)條件會(huì)返回一個(gè)符合條件的新數(shù)組 ?對原數(shù)組不會(huì)造成改變
?let arr2 = arr.filter(function(item,index){
? ? ? ? ? ? return item.price>1500
? ? ? ? })
? ? ? ? console.log(arr2,arr)