var profileDataCalls = [];

profileDataCalls['Profile'] = GetUserAttributesWithDataByGroup;
profileDataCalls['Address'] = GetUserAddresses;
profileDataCalls['Phone'] = GetUserPhoneNumbers;
profileDataCalls['Certs'] = GetUserCertifications;
profileDataCalls['Licenses'] = GetUserLicenses;
profileDataCalls['Notes'] = GetUserNotes;

我的问题是上面的JavaScript数组只有0的长度。我需要一个可以迭代的数组并保存key(string)和value?

最佳答案

你要:

var profileDataCalls = {
    'Profile' : GetUserAttributesWithDataByGroup,
    'Address' : GetUserAddresses,
    'Phone' : GetUserPhoneNumbers,
    'Certs' : GetUserCertifications,
    'Licenses' :GetUserLicenses,
    'Notes' : GetUserNotes
};

然后,您可以使用profileDataCalls.profileprofileDataCalls[profile]访问值(以检索变量GetUserAttributesWithDataByGroup表示的任何值)

要遍历该对象,请使用:
for (var property in profileDataCalls) {
    if (profileDataCalls.hasOwnProperty(property)) {
        console.log(property + ': ' + profileDataCalls[property));
    }
}

09-26 17:27