[javascript] jQuery multiple conditions within if statement

What is the syntax for this loop to skip over certain keys? The way I have it written is not working properly.

 $.each(element, function(i, element_detail){
    if (!(i == 'InvKey' && i == 'PostDate')) {
        var detail = element_detail + ' ';
        $('#showdata').append('<div class="field">' + i + detail + '</div>');
       }
 });

This question is related to javascript jquery

The answer is


Try

if (!(i == 'InvKey' || i == 'PostDate')) {

or

if (i != 'InvKey' || i != 'PostDate') {

that says if i does not equals InvKey OR PostDate


i == 'InvKey' && i == 'PostDate' will never be true, since i can never equal two different things at once.

You're probably trying to write

if (i !== 'InvKey' && i !== 'PostDate')) 

A more general approach:

if ( ($("body").hasClass("homepage") || $("body").hasClass("contact")) && (theLanguage == 'en-gb') )   {

       // Do something

}