Is it possible to coerce captured values into numbers from within replace() in JavaScript?
<p>If I were to replace all occurrences of <code>{n}</code> in a string with the captured value, like so:</p>

<pre><code>"Replacing {1} multiple {2} occurrences.".replace(/\{(\d)\}/g, "$1")
</code></pre>

<p>The result would correctly be:</p>

<pre><code>Replacing 1 multiple 2 occurrences.
</code></pre>

<p>Additionally, if I were to check the <code>typeof</code> replacement <code>"$1"</code>:</p>

<pre><code>"Replacing {1} multiple {2} occurrences.".replace(/\{(\d)\}/g, typeof "$1")
</code></pre>

<p>I would get the expected result:</p>

<pre><code>Replacing string multiple string occurrences.
</code></pre>

<p><strong>What I Would Like To Do:</strong></p>

<p>However, what I would like to do is use the captured values as array indexes and to do that, I would like to coerce the captured values into numbers with <code>parseInt</code>, like so:</p>

<pre><code>"Replacing {1} multiple {2} occurrences.".replace(/\{(\d)\}/g, parseInt("$1"))
</code></pre>

<p>Unfortunately, this returns:</p>

<pre><code>Replacing NaN multiple NaN occurrences.
</code></pre>

<p><strong>My Question:</strong></p>

<p>Why am I unable to coerce these captured values into numbers?</p>
