2022-02-14

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)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容