现在,我得到一个 URL 的最后一部分来排除这样的文件名:
attachmentFileName = attachmentLink.split("/");
attachmentFileName = attachmentFileName[attachmentFileName.length-1];
感觉好像我只能在一个语句中做到这一点,但我不知道如何做。 没什么大不了的,但我认为可以做得更优雅。
最佳答案
您可以使用 Array.prototype.pop()检索拆分数组的最后一个元素的方法:
attachmentFileName = attachmentLink.split("/").pop();
关于javascript - 如何用一行代码获取字符串数组的最后一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852327/