小程序 for循环 报错 Cannot read property 'total' of undefined

问题

for循环一直报错  Cannot read property 'total' of undefined,total在起初是有定义。

原因

是i<=的问题,改为<不报错了。infoArea长度为2,也就是i 应该循环2次。但是写成<=后,i 取值依次是:0,1,2,取值为2时,找不到对应的元素。

infoArea: [
     { title: '打印1', colorType: '彩色双面', count: 2, pages: 20, total: 40 },
     { title: '打印2', colorType: '黑白单面', count: 3, pages: 10, total: 30 }
]

原文地址:https://www.cnblogs.com/lemoncool/p/8258152.html