Events.js: Check if array exists before loop