Javascript在循环中添加对象

时间:2017-10-27 20:05:57

标签: javascript

您好我想知道如何使用for循环

在对象中添加所有值
var myBills = {
    myMumAndDad: 1000,
    myFamily: 2500,
    myPhone: 550,
    myTrain: 650,
    myTraining: 200,
    myInternet: 200,
    myAdobe: 200,
    myElectric: 400,
    myWeb: 100,
    myEditor: 100,
    myRent: 3000,
    myFood: 2000,
};

// Få lavet et loop til at + disse sammen
var allBills = myBills.myMumAndDad + myBills.myFamily + myBills.myPhone + myBills.myTrain + myBills.myTraining + myBills.myInternet + myBills.myAdobe + myBills.myElectric + myBills.myEditor + myBills.myWeb + myBills.myRent + myBills.myFood;

1 个答案:

答案 0 :(得分:1)

TopLevelObject