Within my code, I am dealing with an array named
var mya = ["someval1", "someotherval1", "someval2", "someval3"];
. The goal is to have a function that receives an object with a property set to one of these values.
Instead of simply iterating over the array using a for loop, it might be more efficient to utilize a switch statement considering the static nature of the array and the specific tasks associated with each property.
I am trying to implement this functionality using a switch statement in the following pseudo code:
switch(mya.forEach) {
case "someval1":
alert("someval1");
break;
...
default:
alert("default");
break;
}
However, this code snippet only executes once.
It seems that there may not be a simpler way to combine a forEach loop and a switch statement as desired.