How do I remove eval() from the following code .... - Javascript
<p>I've been using eval in my code and I recently found out that there can be serious security issues If eval() is used inside Javascript. The most common scenario is where I'm using eval() to compose a variable name and then get the value of that variable like here;</p>

<pre><code>var a = "2"        // could be any value

work(a);

function work(a)
{
var l1 = "something";
var l2 = "something else";
var l3 = "something different";

alert(eval("l"+a));
// alerts "something else"
};
</code></pre>

<p>Are there any alternatives to eval() in a situation like this ??</p>

<p>I've tried using window["l"+a] but that will only work if the variables were global and also document.getElementById("l"+a) and that doesn't work either.</p>

<p>Any help greatly appreciated.</p>

<p>Thanks,
Norman.</p>
