2

JavaScript basename()

 2 years ago
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.
neoserver,ios ssh client

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

[2]Python basename


Author: Siong-Ui Te Category: JavaScript

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK