Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "/" in JavaScript location.pathname return value

I request the javascript guru masters again!

Okay this is probably simple, blowing my mind atm.

Example: http://example.com/page.php

var path = location.pathname;

Returns: /page.php

I would like it to not include the first / so it would return page.php

Thank you guru masters!

like image 774
jemiloii Avatar asked Nov 17 '25 22:11

jemiloii


1 Answers

You just need to use one of the several substring functions.

var path = location.pathname.substr(1);

Update: substr is now a deprecated method, so you should use slice instead.

var path = location.pathname.slice(1);
like image 58
Keith Avatar answered Nov 20 '25 10:11

Keith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!