I'm building an ajax response and facing a problem. I want to iterat over a array in JS and render an each element with a different URL, but the URL is not changing with every element inside the array. Here's my example and code:
transcript_list = ['first_element_value','second_element_value']
var len = transcript_list.length
for (var i = 0; i < len; i++) {
$(".transcript").append('<a href = /web_data/output/' + transcript_list[i] + '>' + transcript_list[i] + '</a>' + '|');
}
If I have two elements in the array I can get the first url as
/web_data/output/first_element_value
but for second url on second element I can only get the URL as
/web_data/output/
which missing the second_element_value at the end of the URL. Can't figure out what is going on.
transcript_listandlen?len? Not strictly related (depending on the real values in the strings) but IMO HTML attribute value strings should be quoted to avoid potential issues.transcript_listwithtranscript, usetranscript.lengthinstead oflen) it works fine. I have put the fixed code into an answer as a snippet; this allows people to experiment easily.