Search code examples
javascriptgoogle-maps-api-3infowindow

How to set infoWindow content from an array Google Maps API


I am trying to populate infowindow content from an array:

var arrayTest = ["a", "b"];
infoWindow.setContent("<p>Header</p>" + arrayTest.map(function (val) { return "<p>" + val + "</p>" }));
infoWindow.open(map, marker);

The following is returned:

enter image description here

How do I prevent the comma from being printed within the infoWindow?


Solution

  • You can use the .join() method to change your concatenation default char that is the comma

    var arrayTest = ["a", "b"];
    infoWindow.setContent("<p>Header</p>" + arrayTest.map(function (val) { return "<p>" + val + "</p>" }).join(""));
    infoWindow.open(map, marker);