If your are using ionic v1 then try to read angularjs documentation for basic javascript programming questions,
there is angular.isUndefined() or angular.copy() read more about it.
I donβt really like how this looks like, try to improve your API response in order to access to a propierty and not to a index position.
The above function call is a asynchronous. So it will not wait till its execution to continue loop, that is the reason loop is getting finished first before it executes that method.