0

I have a simple javascript map which does not contain identifiers for the fields. I can iterate through the map but can not obtain the values without the field identifiers.

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]);
}

I know this should be simple but i can not find a solution. Any help would be appreciated. Thanks

6
  • 4
    You just need processStatusTypes[index], It a simple object with primitive values. What exactly you need?
    – Satpal
    Commented Jan 4, 2017 at 10:11
  • I don't think that's a real "map" developer.mozilla.org/en/docs/Web/JavaScript/Reference/… What I see here, is just a regular object.
    – Yoeri
    Commented Jan 4, 2017 at 10:16
  • processStatusTypes[index] will fetch the value of key indexed by 'index' and processStatusTypes[index][0] will fetch first character of value of key indexed by 'index', so to get values just specify processStatusTypes[index]
    – Ankush G
    Commented Jan 4, 2017 at 10:16
  • @Satpal processStatusTypes[index] just gives the whole element at index, not the individual key and value.
    – Ahmet
    Commented Jan 4, 2017 at 10:54
  • @Ahmet, index is key in this scenario. Just test console.log(index, processStatusTypes[index]);
    – Satpal
    Commented Jan 4, 2017 at 10:57

1 Answer 1

1

You're looking for 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]]);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.