Browse - programming tips - javascript dirname basenameDate: 2011feb4 Language: javaScript Q. How about a dirname() and basename() for javaScript? A. The approach is the same in both - remove the characters we don't want. function basename(path) { return path.replace(/.*\//, ''); } function dirname(path) { return path.replace(/\/[^\/]*$/,''); }
Add a commentSign in to add a comment | Advertisements:
|