var profileDataCalls = [];
profileDataCalls['Profile'] = GetUserAttributesWithDataByGroup;
profileDataCalls['Address'] = GetUserAddresses;
profileDataCalls['Phone'] = GetUserPhoneNumbers;
profileDataCalls['Certs'] = GetUserCertifications;
profileDataCalls['Licenses'] = GetUserLicenses;
profileDataCalls['Notes'] = GetUserNotes;
Run Code Online (Sandbox Code Playgroud)
我的问题是上面的JavaScript数组只有0的长度.我需要一个可以迭代的数组并保存键(字符串)和值?
你要:
var profileDataCalls = {
'Profile' : GetUserAttributesWithDataByGroup,
'Address' : GetUserAddresses,
'Phone' : GetUserPhoneNumbers,
'Certs' : GetUserCertifications,
'Licenses' :GetUserLicenses,
'Notes' : GetUserNotes
};
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用,例如,profileDataCalls.profile或访问值profileDataCalls[profile](以检索由变量表示的任何值GetUserAttributesWithDataByGroup)
要遍历对象,请使用:
for (var property in profileDataCalls) {
if (profileDataCalls.hasOwnProperty(property)) {
console.log(property + ': ' + profileDataCalls[property));
}
}
Run Code Online (Sandbox Code Playgroud)