title: Generate string from integer with arbitrary base in JavaScript
body: <p>In JavaScript you can generate a string from a number like this:</p>
  
  <pre><code>(123).toString(36) // =&gt; "3f"
  </code></pre>
  
  <p>If you try to do arbitrary base:</p>
  
  <pre><code>(123).toString(40)
  </code></pre>
  
  <p>You get</p>
  
  <pre><code>Uncaught RangeError: toString() radix argument must be between 2 and 36
      at Number.toString (&lt;anonymous&gt;)
      at &lt;anonymous&gt;:1:7
  </code></pre>
  
  <p>Wondering how to do this to generate a string given an arbitrary alphabet. So say you have this alphabet:</p>
  
  <pre><code>abcdefghijklmnopqrstuvwxyz0123456789+-
  </code></pre>
  
  <p>Then it would be like:</p>
  
  <pre><code>toString(123, 'abcdefghijklmnopqrstuvwxyz0123456789+-')
  </code></pre>
  
  <p>And it would print something out (I have no idea what) such as <code>3+</code>, picking from the alphabet.</p>
  
  <p>Wondering how to do this in JavaScript, not sure if the "radix" has anything to do with it. Thank you.</p>
  
  <p><strong>Update</strong>: Looking how to reverse it as well, aka <code>fromString(string)</code>.</p>