Javascript take script server side
<p>How can I take this code</p>

<pre><code>&lt;script&gt;
var arr = [&lt;%= myArray %&gt;+&lt;%= my2Array %&gt;]; 
var sorted_arr = arr.sort(); 
var results = []; 
for (var i = 0; i &lt; arr.length - 1; i += 1) { 
        if (sorted_arr[i + 1] == sorted_arr[i]) { 
                results.push(sorted_arr[i]); 
        } 
} 
 document.write(results +"&lt;br /&gt;");
&lt;/script&gt;
</code></pre>

<p>and convert it to &lt;% the above script %> and keep the functionality?</p>

<p>Why does the script work in the script tag but not when I place it in &lt;% %></p>

<pre><code>    &lt;%
var arr = [myArray+my2Array]; 
var sorted_arr = arr.sort(); 
var results = []; 
for (var i = 0; i &lt; arr.length - 1; i += 1) { 
        if (sorted_arr[i + 1] == sorted_arr[i]) { 
                results.push(sorted_arr[i]); 
        } 
} 
%&gt;
&lt;%= results %&gt;
</code></pre>

<p>If I use it like this the results are returned as empty</p>

<p>I suspect the reason why it is not working is because the results value is not getting populates... In the script version it gets the time to populate and loop</p>
