2
JavaScript basename()
source link: http://siongui.github.io/2012/10/02/javascript-basename/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
JavaScript basename()
Updated: February 20, 2015
JavaScript basename
/** * JavaScript version of basename * @param {string} path Example: a/b/c/d * @return {string} Example: d */ basename = function(path) { var array = path.split('/'); return array[array.length - 1]; };
Warning
The above code may not be robust for some cases like abc or /a/b/c/
References:
[1][JavaScript] String startswith, endswith and contains Implementation
Author: Siong-Ui Te ∈ Category: JavaScript
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK