es6中数组遍历的方法

//for of
let arr = [1,2,3,4,5]
for(let item of arr){
   console.log(item)
}

es6新增加的for of方法不仅可以遍历数组和对象,还可以遍历自定义的数据结构

场景:到超市向老板要最便宜的香肠,打火机,啤酒等,老板肯定要从存货里算下哪个是最便宜的

const Price = {

    A:[1.5,2.3,4.5],

    B:[3,4,5],

    C:[0.5,0.8,1.2]

}

如何遍历出1.5, 3, 0.5 后续补充

猜你喜欢

转载自www.cnblogs.com/qjb2404/p/12202836.html