The code looks reasonable but, window.ImgArr might not be available to your function or, for some reason, it might not be getting called. Easiest way to test that is:
If both alerts fire, and the second one displays all the contents of ImgArr, then the code is firing and the array is available. If not, we will have to work on one or the other of those issues. Easiest way for me to trouble shoot something like this is to have a link to it.
PLEASE: Include the URL to your problematic webpage that you want help with.