I am really not sure how to write the code. How do I get all the headings from the page? To be specific,
core/heading. I wanted to make a sidebar so that the user can just jump from one section to another. Please see the image below.
Update on this. I got the answer! I followed this simple code from https://goran-s.in.rs/table-of-contents-wordpress-without-plugin/
It's working fine!