let headings = [];
document.querySelectorAll('h2').forEach((heading,index) => {
heading.setAttribute('id', index);
headings.push(heading.innerText);
})
let tocContainer = document.getElementById('toc');
let tocList = `<ul>`;
headings.forEach((heading,index) => {
tocList += `<li><a href="#${index}">${heading}</a></li>`
})
tocList += `</ul>`;
tocContainer.innerHTML = tocList;