JavaScript basename()


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