I have problem to push some value that assigned to be an array in the object
Here my code :
var hasil = [{ product: 'listBarang[i][0]',
shoppers: [],
leftOver: 'listBarang[i][2]',
totalProfit: 0
}]
What I think is using push method like below
hasil.shoppers.push('test')
But it give me an error like this
TypeError: Cannot read property 'push' of undefined
Is anyone know how to deal with this?
hasil
是一个对象数组,因此,如果要处理这些对象,则需要直接访问它们,即使用hasil[0]
:
hasil[0].shoppers.push('test')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.