for循环
computed:{
totalprcie(){
let arr=0;
for (let i = 0; i < this.books.length; i++) {
arr += this.books[i].price;
}
return arr;
}
}
for in
computer:{totalPrcie(){
let arr=0;
for(let i in this.books){
arr += this.books[i].price;
}
return arr;
}}
for of
computer:{
totalPrcie(){
let arr=0;
for(let item of this.books){
arr += item.price;
}}
for each
totalPrcie(){
// let arr=0;
// this.books.forEach(item=>{
// arr+=item.price
// })
// return arr;
// }
map()
computer:{
totalPrcie(){
let arr=0;
this.books.map(item=>{
arr+=item.price
})
return arr;
}}
filter
computer:{
totalPrcie(){
let arr=0;
this.books.filter(item=>{
arr+=item.price
})
return arr;
}}
reduce
computer:{
totalPrcie(){
return this.books.reduce(function(total,item){
return total+item.price
},0)
}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)