I have one variable named hit containing one array, and I have the next codeJavascript if (hit.length > 0) { const entity = getHit(hit); if (entity !== undefined) { entity.triggerEvent(eventName_1); } }which triggers one event (asigned to the variable named eventName_1) when the getHit method (which is a "for loop" to extract the values of the array) returns a value different from undefined from the array named hit.
And I need to trigger (triggerEvent) another different event (eventName_2) in the same entity when the array hit is empty (hit.length === 0), but triggerEvent fires an error when a variable containing undefined calls it, so I think I need to define a new array (e.g. a variable named hitList) containing the values of the array named hit and make it so it never becomes empty, that way I can call the getHit method with the new array (getHit(hitList)) just when getHit(hit) becomes undefined.