cart = [
{
"name": "item1",
"sellingprice": 30,
"barcode": 1494857
},
{
"name": "item2",
"sellingprice": 60,
"barcode": 1235858
},
{
"name": "item3",
"sellingprice": 100,
"barcode": 1568858
}
]
function totalbill(){
Object.keys(cart).forEach(key => {
total += cart[key].sellingprice;
});
console.log(total);
output: 3060100
it works doing it manually
console.log(cart[0].sellingprice+cart[1].sellingprice+cart[2].sellingprice);
output: 190
Also tried using parseInt() didnt word
First of all, have you tried declared the total var before the method totalbill?
And then you can try: