I have an array of values:
const array = ['first', 'second', 'third', 'fourth'];
I want to use each of the values as a case in a switch statement:
switch (???) {
case 'first':
console.log('This is first');
break;
case 'second':
console.log('This is second');
break;
case 'third':
console.log('This is third');
break;
case 'fourth':
console.log('This is fourth');
break;
default:
console.log('None');
}
Values in an array are generated automatically, so it is not a fixed-size array. I can't come up with an expression in between parentheses. Should this be done somehow with a forEach? Should I first split values? But what then? Store them in a separate variable?