curtisp curtisp - 1 month ago 5
Javascript Question

Javascript concatenating string and variable to create url - but doesn't output "/" slashes

I am building HTML in JavaScript which is working fine however I have encountered something haven't seen before and am not finding obvious solution to get past this.

I am trying to create url by concatenating string and variable but it isn't outputting

"/"
slashes.

I am building on the
html
variable which starts off creating a table:

var html = '<table class="table table-bordered">';
html += '<td><a href="https://twitter.com/' + columns[1] +'">' + columns[1] + '</a></td>';


However this outputs everything except the
"/"
slashes and adds
</href="https:>
in place of
</a>
:

<a href="https: twitter.com="" toptechstaffing"="">TopTechStaffing</href="https:>


Is this not possible in JavaScript? In other languages I have seen use of backslashes to escape foreslashes so they can be presented eg
"\/"


What is the "common" way of doing this in JavaScript?




Edited to add:

The
columns[1]
variable was a string.

Answer

Something like this?

var html = "";

html += "<td><a href=\"https://twitter.com/" + columns[1] + "\">" + columns[1] + "</a></td>";