find the name of a directory in javascript

To find the name of a directory in javascript, you can use the split() method on the window.location.pathname property. This will give you an array of all the directories in the path. You can then use the pop() method to get the last item in the array, which is the name of the current directory.

Here's an example:

index.tsx
const pathArray = window.location.pathname.split('/');
const currentDirectory = pathArray.pop();

console.log(currentDirectory); // output: "directory_name"
157 chars
5 lines

This code will give you the name of the current directory in the console. Of course, you can modify it to suit your needs or use it in a function to perform other operations based on the name of the directory.

gistlibby LogSnag