JavaScript handles strings and arrays very well. Sometime its needed to get the last segment or file name of the current page URL and process it for another JavaScript/Ajax request.
Here, I would like to share a fairly easy way.
Let current page URL is http://www.sidd3.com/segment1/segment2/segment3/segment4
Code Example:
![Get Last Segment of URL in JavaScript](https://360adaptive.com/assets/uploads/Screenshot_2019-05-21_at_11.57.16_AM_.png)
For the same purpose, JavaScript array function pop() can be used.
Code Example:
![](https://360adaptive.com/assets/uploads/Screenshot_2019-05-21_at_11.59.26_AM_.png)