jeudi 31 janvier 2019

Sorting vs if else if in javascript which one to choose?

I have a scenario in which I need to display the data in an increasing order of the index number.

myArray = [
{custom_carousel: false, default_label: "SmartCards", index: 3, visible: true}, 
{custom_carousel: false, default_label: "Pathways", index: 2, visible: false},
{custom_carousel: false, default_label: "Pathways", index: 1, visible: false},
{custom_carousel: false, default_label: "Pathways", index: 0, visible: false}
]

Should I first sort the array or add if else if condition ?

if(index === 0){

}else if (index === 1){

}else if (index === 2){

}else if (index === 3){

}


Aucun commentaire:

Enregistrer un commentaire