我有一个简单的javascript映射,其中不包含字段的标识符。我可以遍历地图,但是没有字段标识符就无法获取值。
var processStatusTypes = {
1:'ClaimProcess Status 1',
2:'ClaimProcess Status 2',
3:'ClaimProcess Status 3',
4:'ClaimProcess Status 4',
5:'ClaimProcess Status 5',
6:'ClaimProcess Status 6',
7:'ClaimProcess Status 7'
};
for (var index in processStatusTypes) {
console.log(processStatusTypes[index][0]);
console.log(processStatusTypes[index][1]);
}
我知道这应该很简单,但是我找不到解决方案。任何帮助,将不胜感激。谢谢
最佳答案
您正在寻找Object.keys
var processStatusTypes = {
1:'ClaimProcess Status 1',
2:'ClaimProcess Status 2',
3:'ClaimProcess Status 3',
4:'ClaimProcess Status 4',
5:'ClaimProcess Status 5',
6:'ClaimProcess Status 6',
7:'ClaimProcess Status 7'
};
var keys = Object.keys(processStatusTypes);
for (var i = 0;i<keys.length;i++) {
console.log(keys[i], processStatusTypes[keys[i]]);
}