Yes. I had to mention it. Put the array declaration itself in the global scope (outside the onClick function).