In order to find the name of a file in JavaScript, you can use the split()
method. First, you need to get the full path of the file as a string. For example:
index.tsx44 chars2 lines
Then, you can split the string by the forward slash character ("/"), which will give you an array of strings:
index.tsx33 chars2 lines
The last element of the array will be the file name:
index.tsx40 chars2 lines
Now, the fileName
variable will contain the name of the file, which in this case is "example.txt".
gistlibby LogSnag