order.amount is a string, and if one of the operands of the + operator is a string, concatenation is performed instead of the sum.
You must convert it to a number, for example, using the unary plus operator:
var totalAmt = 0, i, order;
for (var i in orders) {
order = orders[i];
if (order.status !='Cancelled')
totalAmt += +order.amount;
}
Alternatively you can use:
totalAmt = totalAmt + (+order.amount);
totalAmt = totalAmt + Number(order.amount);
totalAmt = totalAmt + parseFloat(order.amount);
// etc...
Also you use for..in loop to iterate over orders, if orders- an array, you should use a regular loop:
for (var i = 0; i<orders.length; i++) {
}
, for...in , , , , , , Array.prototype, .
- , , , , , , , , .
, :
var i = orders.length;
while (i--) {
}