While you have the choice to make the TOC however you want, there's absolutely no reason to use a JavaScript solution since Asciidoctor has a built-in TOC generator. The benefit of the built-in TOC generator is that it ignores discrete headings (headings which are not part of the document outline).
There are two ways to get a TOC. First, you can simply set the toc attribute on the document and the toc will get added at the top of the page.
The other way is to use the TOC support provided by Jekyll AsciiDoc. This allows you to place the TOC in a template. See
Is there a specific question you had about tocify_asciidoc?