Latex – tip for disabling *sections in table of contents

I’ve just found solution for disabling ‘subsection’ or ‘subsubsection’ from table of contents in latex.
What’s important that solution doesn’t affect ‘*section’ number in text.

To disable subsubsections in TOC write:

  \tableofcontents
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}

To disable subsections in TOC write:

  \tableofcontents
  \addtocontents{toc}{\protect\setcounter{tocdepth}{1}}

Source