Create this to answer the question.
Is there a JavaScript solution to generating a "table of contents" for a page?
I have answered the question already. So you can click Run code snippet to see the result.
Note it's better to Expand the page (full page) when you run.