let books =[{name:"JavaScript从入门到入土", price:119},{name:"Java从入门到放弃", price:80},{name:"编码艺术", price:99},{name:"代码大全", price:150}]
常用for循环
let result =0;for(let i =0; i < books.length; i++){
result +=this.books[i].price;}
for…of…
let result =0;for(let i of books){
result += i.price;}
for…in…
/*
hasOwnProperty() 判定自身属性是否存在
使用for...in...需要使用hasOwnProperty() 进行检测当前循环的值
*/let result =0;for(let i in books){if(books.hasOwnProperty(i)){
result += books[i].price
}}
数组.forEach()
/*
item: 数组中当前处理的元素
index: 索引
array: 当前数组 // this.books
*/let result =0;this.books.forEach((item, index, array)=>{
result += item.price
})