$ .each on Enum jQuery

I have an Enum defined in my Javascript as shown below:

BankTypesEnum = {
        'Savings': '0',
        'HomeLoan': '1',
        'Current': '2',
       'salary': '3'
    }

I want to run $.each()on this and compare with values ​​from another data source. Can someone help me with this?

+5
source share
3 answers
$.each(BankTypesEnum , function(key, value) { 
  alert(key + ': ' + value); 
});

edit this code according to your needs, instead of specifying a comparison or anything else you need to do with keys and values

+8
source

Do you need to use $ .each ()? If going through them is the goal, you can simply use for for in a loop like this:

var earnings=BankTypesEnum;
for(var myEarnings in earnings)
{
    //do something here
}
+3
source

try it

BankTypesEnum = {
    Savings: 0,
    HomeLoan: 1,
    Current: 2,
    salary: 3
}

$.each(BankTypesEnum, function(i, data) {
    console.log(i + ' - ' + data)
});​

Note FIDDLE

+1
source

All Articles