user2128 user2128 - 2 years ago 63
Javascript Question

Return array int value of the respective String javascipt

In the code below, priorityData array is in [80]="High" format i.e 80 is the integer value of High. I want to extract and use integer value 80 whenever my string is equivalent to "High". How should i do that?

if (service.priorityData[i] === priorityString) {"Priority string", service.priorityData[i].values());
return service.priorityData[i].values();
} else {
return null;

service.priorityData = {0 : "None", 20: "Low, 80: "High"}

But it doesnt return anything when i use this code. Can someone please point out my mistake. Thanks

Answer Source

Simply loop through the object and return the key when the value matches what you want.

for (var key in service.priorityData) {
    if (service.priorityData[key] == priorityString) {
        return key;
    return null; // not found
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download