 <p>Although <code>alert(some_array)</code> prints a string representation of the array, the array itself is not a string. Thus, it does not have <code>.replace</code>. <code>alert</code> is forced to convert it into a string because the alert box can only show characters.</p> <p>You can simply join using a custom separator, though. <code>join</code> is a function of arrays:</p> <pre><code>var all_boxes_values_clean = all_boxes_values.join(", "); </code></pre> <p>As a side note, I recommend <code>console.log</code> over <code>alert</code> because it:</p> <ol> <li>shows the actual object/array instead of a string representation (especially useful with objects instead of the useless <code>[object Object]</code> you receive with <code>alert</code>)</li> <li>frees you from closing the popup each time</li> <li>keeps track of other logs so that you have an actual log of logs</li> </ol>