I was struggling with this as well, but it turns out you need to declare a global array at the top to push the infowindows into.
In case anyone’s interested:
At the top ( after (function($) { ) add var infoWindows = new Array(); , after which you can use the above infoWindows.push(infoWindow); and //close all part to push to and loop through the array.
Make sure to double check the upper/lower case W in infowindow/infoWindows.
Not sure if this is the most efficient way of doing this, but it works.