title: Multiplying a symbol in a string
body: <p>What is the standard way in javascript for replacing each occurrence of a certain symbol in a string with itself n times?</p>
  
  <p>I have text strings where each occurrence of the single-quote symbol needs to be replaced with single-quote symbol doubled, i.e. in place of each occurrence of single-quote must appear two. This is a standard task for pre-parsing text for PostgreSQL calls.</p>
  
  <p>I found out that function replace() isn't suitable for this, i.e. we cannot use it like <code>replace('A','AA')</code>, it doesn't work in this special case when we have a string with repeated symbols like <code>'Test AA'</code>, which we would want to turn into <code>'Test AAAA'</code>.</p>
  
  <p>So, what is the right way to do this?</p>