0
<% for(var i=0; i < 1; i++) { %>
<a href="<%= related[i] %>"> <%= related[i] %> </a>
<% } %>

I need to change related[i] to url format (lowercase, add "-" instead a space, remove some !,/ and more)

Moomoo Soso
  • 99
  • 1
  • 1
  • 7
  • 2
    Possible duplicate of [Encode URL in JavaScript?](http://stackoverflow.com/questions/332872/encode-url-in-javascript) – Erazihel May 01 '17 at 20:57
  • Use [encodeURIComponent()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent). – StackSlave May 01 '17 at 21:01

1 Answers1

0
<% for(var i=0; i < 1; i++) { %>
<a href="<%= related[i].toLowerCase().replace(/ /gi, "-"); %>"> <%= related[i] %></a>
<% } %>

we can add .toLowerCase() and replace(/ /gi, "-") to change string to lowercase and add replace space with "-"

Moomoo Soso
  • 99
  • 1
  • 1
  • 7
  • May I request you to please add some more context around your answer. Code-only answers are difficult to understand. It will help the asker and future readers both if you can add more information in your post. – RBT May 01 '17 at 23:08