0

My array looks like

["John Connor ", "Mike ", "Ryan Jones ", "Markey O ", "Markey B"]

I'm trying to put these into multiple strings (though splitting into multiple strings may not be the best way) so I can place them on the page one below the other.

So I do $(".info_container").text(myArray);

How can I split these at the , and then place them into the DOM?

I tried $(".info_container").text(myArray).join(","); but this still just gives me a string of arrays not individual strings.

pourmesomecode
  • 4,108
  • 10
  • 46
  • 87

3 Answers3

2

Try:

var array = ["John Connor ", "Mike ", "Ryan Jones ", "Markey O ", "Markey B"];
array.forEach(function(name) {
   $(".info_container").append('<span>' + name + '</span>');
});
jcubic
  • 61,973
  • 54
  • 229
  • 402
2

You can use .innerHTML with arrary.join(', <br>'):

var arr = ["John Connor ", "Mike ", "Ryan Jones ", "Markey O ", "Markey B"];

document.body.innerHTML = arr.join(', <br>');
Jai
  • 74,255
  • 12
  • 74
  • 103
1

You can try this:

var myArray = ["John Connor ", "Mike ", "Ryan Jones ", "Markey O ", "Markey B"].toString();

Then:

$(".info_container").text(myArray);
knnsarsaba
  • 56
  • 2