This is a slightly similar question to javascript switch vs loop on array, but different. Compare
function Function1 (n) {
switch (n) {
case 0:
return "apple";
break;
case 1:
return "pear";
break;
// and a few more, or many more
}
}
and
var Array2 = ["apple", "pear"]; // and more
which you then call or refer to as needed. The second is much neater, but are there any important disadvantages to it, not just in terms of speed, but also memory use? Will the answer change a lot if there are more cases / elements in the array? Is your answer Javascript-specific or a general tenet of programming? Thank you.