1

I have an array of links and would like to use them in a href in Javascript. e.g array[i].link however i'm struggling to get the correct syntax. I've tried multiple ways e.g

"<p>Link</p>" + '<a href="array[i].link"> + array[i].link </a>'

but can't get it to work. Is there a way around it?

3
  • 1
    '<p>Link</p>' + '<a href="' + array[i].link + '">' + array[i].link </a>' Commented Apr 25, 2017 at 22:36
  • So your question is how to do string concatenation correctly? Commented Apr 25, 2017 at 22:36
  • you have to use single quotes in javascript then concatenate the whole thing into one string Commented Apr 25, 2017 at 22:37

3 Answers 3

0
 "<p>Link</p>" + "<a href='" + array[i].link + "'  </a>";
Sign up to request clarification or add additional context in comments.

Comments

0

array[i].link is not a string and therefore should be outside the " quotes.

Comments

0

Keep array[i].link outside the quotation marks, i.e...

'<a href=' + array[i].link + '>'

because it's not a string literal.

Edit:

The post JavaScript var in string may also help answer your question

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.