I have an empty array as follows:
var itemsWithEmptySockets = [];
Which may be populated with one or more of the following values (depending on information pulled via n API):
0, 1, 2, 4, 5, 6, 7, 8, 9, 15, 16
Where:
0 = Head
1 = Neck
2 = Shoulder
4 = Chest
5 = Waist
6 = Legs
7 = Feet
8 = Wrist
9 = Hands
14 = Back
15 = MainHand
16 = SecondaryHand
I'd like to test to see what the array has in it and essentially translate those numbers to strings by storing the string in an array e.g. if 0, then the Head has an empty socket, add "Head" to new array which I'd then like to use to display "Head" as a string within the DOM.
In order to do so I tried a switch statement e.g.
switch(itemsWithEmptySockets){
case 0:
emptyItems.push("Head");
break;
However it appears switch statements don't support the use of arrays in this way i.e. passing the array itemsWithEmptySockets.
Is there a more efficient way to do this than 12 if statements?? e.g.
for(i=0; i < itemsWithEmptySockets.length; i++){
if(itemsWithEmptySockets[i] == 0){
emptyItems.push("Head");
}
if(itemsWithEmptySockets[i] == 1){
emptyItems.push("Neck");
}
etc.
}
Many thanks for the help!
String[16]which contains the strings. You can get the rightStringvalue by indexing this array.