Question: In Javascript, is there a way to achieve something similar to this ?

```
const databaseObjectID = "someId"; // like "product/217637"

switch(databaseObjectID) {
    case includes('product'): actionOnProduct(databaseObjectID); break;
    case includes('user'): actionOnUser(databaseObjectID); break;
    // .. a long list of different object types
}

```

This is more a curiosity question to understand the possibilities of switch / case, as in this particular case I have solved my problem using `const type = databaseObjectID.split('/')[0];` and apply the switch case on `type`

Answer: 
You usage would be considered an abuse of case.

Instead just use ifs 

```
     if (databaseObjectId.includes('product')) actionOnProduct(databaseObjectID); 
else if (databaseObjectId.includes('user'))    actionOnUser(databaseObjectID); 
// .. a long list of different object types

```

If the ObjectId contains static content around the product or user, you can remove it and use the user or product as a key:

```
var actions = {
  "product":actionOnProduct,
  "user"   :actionOnUser
}

actions[databaseObjectId.replace(/..../,"")](databaseObjectId);

```
Question:

> 
> use string “includes()” in switch Javascript case
> 
> 
> 

While the `includes()` method will work, it is case sensitive, and just matches any characters. I have found a Regex solution that I like much better, and provides a lot of flexibility. For example, you could easily change this to match only WORDS.

```js
var sourceStr = 'Some Text and literaltextforcase2 and more text'

switch (true)  {  // sourceStr

  case (/LiteralTextForCase1/i.test(sourceStr)):
      console.log('Case 1');
      break;

  case (/LiteralTextForCase2/i.test(sourceStr)):
    console.log('Case 2');
    break;

  default:
      console.log('ERROR No Case provided for: ' + sourceStr);
};

//-->Case 2
```