Another option is to only use a single Infowindow instead of creating an infowindow for each marker. Then whenever another marker is clicked on the infowindow simply moves to the new location with the new content. In this example the updated code would look like this:
var locationInfowindow = new google.maps.InfoWindow();
function setMarkers(map) {
for (var i = 0; i < locations.length; i++) {
var location = locations[i];
var marker = new google.maps.Marker({
position: {lat: location[1], lng: location[2]},
map: map,
title: location[0]
});
var content = 'Test Content: '+i;
google.maps.event.addListener(marker,'click', (function(marker,content){
return function() {
locationInfowindow.setContent(content);
locationInfowindow.open(map,marker);
};
})(marker,content));
}
}