The app.select() method is not suposed to return anything, so a is undefined.

Better is to set a to myFoundItems[i].parentTextFrames (which is an Array and may be empty) and to remove—with caution—the text frames. Note that removing a container can make a previous myFoundItems[i] invalid during the loop. So I suggest: