How to get multiple strings into one case in Java Script?

So I’ve been using switch statements, and was wondering if there is a way to get several strings into one case, instead of only one string per case.

For example:

switch(fruits) {
case 'apples','bananas','oranges','strawberries':

//I'd like to get those four  fruits into one case, instead of doing this:   
switch (fruits) {
    case 'apples':
    break;
    case 'bananas':
    break;
    case 'oranges':
     break;
     case 'strawberries':

If this can be done it will save me a lot of time.

Source: New Questions

1 Comment

  1. Digin Dominic

    Do not use switch/case when you need multiple value matches. Use IF:
    if(fruits === ‘apples’ ||
    fruits === ‘bananas’ ||
    fruits === ‘oranges’ ||
    fruits === ‘strawberries’){
    //do some action
    }

    Reply

Leave a Reply