遍历数组中的数据的方法

var books = [{name:'西游记',author:'吴承恩',price: 58,count:5},{name:'三国演义',author:'罗贯中',price: 68,count: 6},{name:'水浒传',author:'施耐庵',price: 48,count:8},{name:'红楼梦',author:'曹雪芹',price: 78,count:10}]
(1) 通过for循环 计算总价格

let totalPrice = 0 for(let i=0; i

(2)
let totalPrice = 0 for(let i in this.books) { this.totalPrice += this.books[i].price * this.books[i].count }

【遍历数组中的数据的方法】(3)
let totalPrice = 0 for(let item of this.books) {// item为每一项的下标 totalPrice += item.price * item.count }

    推荐阅读