user1269625
user1269625

Reputation: 3209

Jquery string replace, only replacing the start of array

I have this code here:

<script type="text/javascript">
    var catURL = window.location.pathname;
    var catTitle = catURL.split("/");
    catTitleNew = catTitle[4].replace("-", " ");
    alert(catTitleNew);
    //this will alert will convert this-is-my-title to this is-my-title
</script>

And I dont think my replace code is working, its only replacing the first "-" how to I get it to replace all the "-" ?

Upvotes: 0

Views: 55

Answers (1)

Robb
Robb

Reputation: 2686

catTitleNew = catTitle[4].replace(/-/g, " ");

Fiddle

Upvotes: 4

Related Questions