I'm are working on the dataLayer for our project and I'm pushing title, url, section, subsection, subsubsection & subsubsubsection from the request URL.
Please find the below sample url and split of different sections in the URL.

Please find the below code snippet from dataLayer.html
I want to push data only when it is available. For instance, if I don't have subsubsection in my URL, I don't wish to see even empty subsubsection(subsubsection:"") inside the dataLayer object.
<script language="JavaScript" type="text/javascript">
window.dataLayer = window.dataLayer || [];
var urlWithoutExt = window.location.href.replace(location.search, '').replace(/\.[^/.]+$/, "");
console.log("urlWithoutExt::::"+urlWithoutExt);
var tempsubsection = "";
var tempsubsubsection = "";
var tempsubsubsubsection = "";
if(urlWithoutExt.toString().split("/")[3] != null){
tempsubsection = urlWithoutExt.toString().split("/")[3];
}
if(urlWithoutExt.toString().split("/")[4] != null){
tempsubsubsection = urlWithoutExt.toString().split("/")[4];
}
if(urlWithoutExt.toString().split("/")[5] != null){
tempsubsubsubsection = urlWithoutExt.toString().split("/")[5];
}
window.dataLayer.push({
event: 'content_landing',
eventInfo: {
title: '${currentPage.title || currentPage.name @ context="text"}',
url: window.location.href.replace(location.search, ''),
section: window.location.hostname,
subsection: tempsubsection,
subsubsection: tempsubsubsection,
subsubsubsection: tempsubsubsubsection
}
});
</script>
Please find the below browser console - From the dataLayer object, there is n't any subsubsection or subsubsubsection and we are seeing empty values for the both. (Actual Result)
I expect both subsubsection & subsubsubsection should not available inside the dataLayer object itself. (Expected Result)

Kindly help me on this problem.
Thank you.
Regards,
SHYAMSUNDAR TK