Question: In my Js script, I am using switch case but I dnt want to use it but I am not getting better alternative of this.

Here I am using Js CONSTANT as well for defining First URL & Second URL

```
var FIRST_URL  = "/first_url.html"
var SECOND_URL = "/second_url.html"

```

& also passing FIRST\_URL and SECOND\_URL as parameter from function. That's why I used FIRST\_URL with double quotes and without quotes.

**Snippet :-**

```
if(url == "DIV_ID"){

  switch (url_type) {
    case FIRST_URL:
    case "FIRST_URL":
      result = "/first_url.html";
      break;
    case SECOND_URL:
    case "SECOND_URL":
      result = "/second_url.html";
      break;
    default:
      result = "other_url.html";
      break;
  }
} 

```

Suggest something to resolve this.

Answer: 
You can use something like this, but add proper error checking.

Roughtly:

```
var arr = {};
arr['FIRST'] = 'your first url';
arr['SECOND'] = 'your second url';
result = arr[urlType];

```
here's an example using object literal:

```js
var arr = {
  FIRST : 'your first url',
  SECOND: 'your second url'
   };

console.log(arr.FIRST)
console.log(arr['SECOND'])

//for adding properties
 arr.thr='third prop';
```

basically the resulting obj is the same to bigmike's answer, but it maybe easier to understand .

This is what is called a key-value pair and the structure is an object (JS definitions).

BTW there is nothing wrong with switch .