var path = window.location.pathname; path = '/ru/video/'; // example var level = path.split('/').filter(Boolean).length; alert(level);