1、过滤数组 -filter
筛选数组元素,并生成新数组
//过滤出分数为60分以上的数据
<script>
const arr = [
{'name':'张三','score':80},
{'name':'张六','score':50},
{'name':'李四','score':90},
{'name':'王五','score':60},
]
const newArr = arr.filter(function(item,index){
return item.score>=60
})
console.log(newArr)
</script>
2、迭代数组-map
返回新数组,新数组里面的元素是处理之后的值,经常用于处理数据
<script>
//给数据的分数都加上10分
const arr = [
{'name':'张三','score':80},
{'name':'张六','score':50},
{'name':'李四','score':90},
{'name':'王五','score':60},
]
arr.map(function(item,index){
item.score+=10
})
conso
标签:map,arr,name,reduce,js,60,item,score,数组
From: https://blog.csdn.net/cyc799/article/details/140790258