You can pass instances around directly, so you generally don't need UIDs. If you have already got an instance reference, you can just keep using it, there's no need to loop through all instances.
I'm still making the same point: you need to think about scripting with a different approach.
You can't save instances to storage though, so I guess you need UIDs for that. I'll look in to adding a scripting method to get an instance by its UID, but as I keep repeating, this isn't something you should need for general purpose code. I am sure there are pure JS engines out there that do not use anything like UIDs at all. You can go a long way without them in code.