To find the extension of a file in Javascript, you can first get the name of the file and then find the last index of the "." character to extract the extension.
Here's an example code snippet:
index.tsx148 chars4 lines
In the above example, we first defined the fileName
variable with the name of the file. Then, we used the slice
method to extract the substring after the last occurrence of the "." character in the file name, which gives us the file extension.
Finally, we logged the value of fileExtension
to the console.
gistlibby LogSnag