Hi! Formatting TOC numbers with leading zeroes isn’t built into the default behavior, unfortunately.
So theres no official option in R Markdown or Quarto (assuming you're using one of those) to automatically format TOC numbers with leading zeroes out of the box. As you noted, the default just uses plain integers.
If you’ve already tried a JS-based workaround, you’re not over engineering, that’s actually the most common approach when native options are missing. Another (slightly hacky) alternative could be to manually prefix your section headers with 01 , 02 , etc, but that obviously doesn't scale well or work with auto-generated TOCs.
So while it might feel like a bit much, your JS method is probably the cleanest and most flexible solution until a native setting is added. If it's any comfort, others have resorted to the same.
Would be great to see this as a feature request upstream, honestly!