I have a list with paths as below:
<ul class="list">
<li class="item">/animal/dog/treats/biscuits</li>
<li class="item">/animal/dog/treats/cookies</li>
<li class="item">/clothes/shirts</li>
</ul>
I want to convert each of the paths in the above list into a nested unordered list as shown below using JavaScript:
<ul>
<li>animals
<a href="/animal">Shop</a>
<ul>
<li>dogs
<a href="/animal/dog">Shop</a>
<ul>
<li>treats
<a href="/animal/dog/treats">Shop</a>
<ul>
<li>
<a href="/animal/dog/treats/biscuits">biscuits</a>
</li>
<li>
<a href="/animal/dog/treats/cookies">cookies</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>clothes
<a href="/clothes">Shop</a>
<ul>
<li><a href="/clothes/shirts">shirts</a></li>
</ul>
</li>
</ul>
Here is the expected output: output
If anyone could please steer me in the right for achieving this using JavaScript, I'd really appreciate it. Thank you!