JS: Most optimized way to remove a filename from a path in a string?

#javascript #optimization
author's avatar
Kees de Kooter
Today 12:28

Use lastIndexOf() to find the position of the last slash and get the part before the slash with substring().

str.substring(0, str.lastIndexOf("/"))