Getting just the filename from a path with JavaScript

前端 未结 6 555
醉话见心
醉话见心 2020-12-08 04:56

I have a full path to an image, which I am using jQuery to read like this:

$(\'img.my_image\').attr(\'src\');

However I just want the f

6条回答
  •  既然无缘
    2020-12-08 05:19

    In Javascript you could do

    function getFileNameFromPath(path) {
      var ary = path.split("/");
      return ary[ary.length - 1];
    }
    

提交回复
热议问题