In JavaScript you can generate a string from a number like this:

```
(123).toString(36) // => "3f"

```

If you try to do arbitrary base:

```
(123).toString(40)

```

You get

```
Uncaught RangeError: toString() radix argument must be between 2 and 36
    at Number.toString (<anonymous>)
    at <anonymous>:1:7

```

Wondering how to do this to generate a string given an arbitrary alphabet. So say you have this alphabet:

```
abcdefghijklmnopqrstuvwxyz0123456789+-

```

Then it would be like:

```
toString(123, 'abcdefghijklmnopqrstuvwxyz0123456789+-')

```

And it would print something out (I have no idea what) such as `3+`, picking from the alphabet.

Wondering how to do this in JavaScript, not sure if the "radix" has anything to do with it. Thank you.

**Update**: Looking how to reverse it as well, aka `fromString(string)`.