How to fix “Uncaught TypeError: Cannot set property '0' of undefined”
问题 Below is the code am trying the figure out, when arrays (bill, tipValue, totalAmmount) are declared within the object method i get "cannot set property '0' undefined error. But, When the same arrays are declared outside the object then i get expected result" code am getting exception: var john = { bill: [124, 48, 268, 180, 42], tipValue: [], totalAmmount: [], calcTip() { this.bill.forEach(function (ele, i) { this.tipValue[i] = innercalc(ele); this.totalAmmount[i] = this.tipValue[i] + ele; });