I have a rather weird issue. I have an array of html-code in string-format that I want to join together and insert into an existing element on my page.
The array looks something like this:
var sample_array = ['<div class="cld-event"><div class="cld-time">12:00</div><div class="cld-description">Some blabla</div></div>', '<div class="cld-event"><div class="cld-time">15:00</div><div class="cld-description">Some blabla</div></div>', ...];
When joining and inserting the array such as:
$(myelement).html(sample_array.join(''));
I weirdly enough get the individual html elements separated by commas, which I of course do not want.
Just logging the array join in the console also returns the elements separated by a comma. I already tried replacing the '' argument in the join method with other strings such as '+', but it doesn’t help either, it’s always the comma that shows up.
I linted the entire code and I have no errors. Has anybody every encountered something like this? I’m sure I’m making some very obvious and very stupid mistake here, but I just can’t figure it out.
Are you sure that you are not including the commas in some way?like adding an extra set of quotes so that you only have one element of the array?
Because the only reason for this is that actually you are joining an array with only one element (so no join is performed and so join(‘+’) is ignored)
what value has
sample_array.length?are you sure your array is not (notice the quotes at the beginning)