Your “test” array variable is either undefined or it is not present in the scope where you are running the loop.
Delare it globally or inside required function using test = [];.
The error message says “test” is undefined. This means test variable is not defined. Use test = [] before using it.
This is not related with selectcity.
JavaScript is a terrible language. Angular exacerbates some of that. You need to follow coding rules that protect you from bugs like this.
Any time you have an object property, initialize it, even if it is just {}.
Any time you have an array property, initialize it, even if it is just [].
I have yet to see a situation where any is necessary in app code, so don’t ever use it.
The entire point of marking something as the solution is that somebody with a similar problem knows exactly where to look. Do you honestly think that the post you marked as the “solution” qualifies?