How to use a RegExp literal as object key?
<p>I would like to use create a object that contains regular expressions as the key value. I tried to use the following syntax:</p>

<pre><code>var kv = {
    /key/g : "value"
};
</code></pre>

<p>But it fails according <a href="http://www.javascriptlint.com/" rel="nofollow">JavaScript lint</a>:</p>

<pre><code>SyntaxError: invalid property id
</code></pre>

<p>How can I fix it?</p>

<h3>Update</h3>

<p>Background: The reason why I want to do this is to implement a workaround that fixes wrong unicode in a HTTP API result. I know this is very hackish, but since I have no control over the API server code I think this is the best I can do.</p>

<p>Currently I implemented the mapping by having a keys array and a values array:</p>

<pre><code>function fixUnicode(text) {

    var result = text;
    var keys = [];
    var values = [];
    keys.push(/&amp;Atilde;&amp;copy;/g); values.push("&amp;eacute;");
    keys.push(/&amp;Atilde;&amp;uml;/g); values.push("&amp;egrave;");
    keys.push(/&amp;Atilde;&amp;ordf;/g); values.push("&amp;ecirc;");
    keys.push(/&amp;Atilde;&amp;laquo;/g); values.push("&amp;euml;");
    keys.push(/&amp;Atilde;&amp;nbsp;/g); values.push("&amp;agrave;");
    keys.push(/&amp;Atilde;&amp;curren;/g); values.push("&amp;auml;");
    keys.push(/&amp;Atilde;&amp;cent;/g); values.push("&amp;acirc;");
    keys.push(/&amp;Atilde;&amp;sup1;/g); values.push("&amp;ugrave;");
    keys.push(/&amp;Atilde;&amp;raquo;/g); values.push("&amp;ucirc;");
    keys.push(/&amp;Atilde;&amp;frac14;/g); values.push("&amp;uuml;");
    keys.push(/&amp;Atilde;&amp;acute;/g); values.push("&amp;ocirc;");
    keys.push(/&amp;Atilde;&amp;para;/g); values.push("&amp;ouml;");
    keys.push(/&amp;Atilde;&amp;reg;/g); values.push("&amp;icirc;");
    keys.push(/&amp;Atilde;&amp;macr;/g); values.push("&amp;iuml;");
    keys.push(/&amp;Atilde;&amp;sect;/g); values.push("&amp;ccedil;");

    for (var i = 0; i &lt; keys.length; ++i) {
        result = result.replace(keys[i], values[i]);
    }
    return result;
}
</code></pre>

<p>But I want to implement to use a JavaScript object to map keys as values:</p>

<pre><code>function fixUnicode(text) {

    var result = text;
    var keys = {
        /&amp;Atilde;&amp;copy;/g : "&amp;eacute;",
        /&amp;Atilde;&amp;uml;/g :  "&amp;egrave;"
        // etc...
    };

    for (var key in keys) {
        result = result.replace(key, keys[key]);
    }
    return result;
}
</code></pre>
