-1

I have the following url :

http://localhost/get/this/url/in/a-nice-format.html

var pagename= location.pathname.split('/').join(':');

gives me

:get:this:url:in:a-nice-format.html

How do I get rid of the first ":"?

Thanks.

wailer
  • 511
  • 7
  • 22
  • Possible duplicate of [Remove first character from a Javascript string](http://stackoverflow.com/questions/3923015/remove-first-character-from-a-javascript-string) – Obsidian Age May 16 '17 at 22:45

3 Answers3

1

pagename = location.pathname.split('/').join(':').substr(1);

Ismoil Shifoev
  • 5,512
  • 3
  • 24
  • 32
0

Hi you can use substrings method. Simply do this.... var pageName2 = pageName.substring(1); I hope this helps.

Samson Iyanda
  • 512
  • 3
  • 13
0

I'm not able to comment yet but waned to help anyway. And there's probably an answer somewhere else...

Anyway, try using slice() and passing in a 'begin' argument of 1 to remove the first ':'.

Like this: var pagename= location.pathname.split('/').join(':').slice(1);

Omar
  • 421
  • 4
  • 10