javascript - Simpler way to combine a if else statement (.contains?) -



javascript - Simpler way to combine a if else statement (.contains?) -

what best way simplify code. thought using .contains i'm unsure how. tell me if need more code.

thank you.

$.each(catalog.products, function(index, value) { if (filtervalue == '' || value.name.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1) { items.push('<li id="' + index + '">' + '<a data-identity="productid" href="./details.page?productid=' + index + '" >' + '<img class="ui-li-thumb" src="' + value.thumbnail + '"/>' + '<p>' + value.brand + '</p>' + '<h3>' + value.name + '</h3>' + '<span class="ui-li-count">' + value.price + ' $</span></li>') + '</a>'; } else if (filtervalue == '' || value.brand.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1) { items.push('<li id="' + index + '">' + '<a data-identity="productid" href="./details.page?productid=' + index + '" >' + '<img class="ui-li-thumb" src="' + value.thumbnail + '"/>' + '<p>' + value.brand + '</p>' + '<h3>' + value.name + '</h3>' + '<span class="ui-li-count">' + value.price + ' $</span></li>') + '</a>'; } } );

it looks simple add-on of or clause top if statement, or missing something?

have tried this?

$.each(catalog.products, function(index, value) { if (filtervalue == '' || value.name.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1 || value.brand.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1) { items.push('<li id="' + index + '">' + '<a data-identity="productid" href="./details.page?productid=' + index + '" >' + '<img class="ui-li-thumb" src="' + value.thumbnail + '"/>' + '<p>' + value.brand + '</p>' + '<h3>' + value.name + '</h3>' + '<span class="ui-li-count">' + value.price + ' $</span></li>') + '</a>'; } } );

javascript jquery arrays list

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -