map循环
let array = [1, 2, 3, 4, 5];
let newArray = array.map((item) => {
return item * item;
})
console.log(newArray) // [1, 4, 9, 16, 25]
find循环
this.state={
nwelist:[
{id:1,title:'这是1'},
{id:2,title:'这是2'},
{id:3,title:'这是3'},
{id:4,title:'这是4'}
]
}
let findResult = this.state.nwelist.find(item=>{
if(4==item.id){
return item
}
})
console.log(findResult)// {id: 4, title: '这是4'}
js map循环与find循环
最新推荐文章于 2024-08-21 09:02:55 发布