mercredi 13 décembre 2017

How to avoid multiple IF to check different condtions

There are multiple IF statements in my code like following:

if ($('#text1').val().length == 0) {
    $('#text1').val(text1);
}
if ($('#text2').val().length == 0) {
    $('#text2').val(text2);
}
if ($('#text3').val().length == 0) {
    $('#text3').val(text3);
}
if ($('#text4').val().length == 0) {
    $('#text4').val(text4);
}
if ($('#text5').val().length == 0) {
    $('#text5').val(text5);
}
if ($('#text6').val().length == 0) {
    $('#text6').val(text6);
}

So based on the requirement I need to check if value is there in the textbox then don't overwrite the API response, if the textbox is blank write the API response. Is there any way to avoid these many IF to improve the performance?

Aucun commentaire:

Enregistrer un commentaire