Well, that is because you are not appending anything to names. I'm not sure why you keep modifying your script, when it was fine, apart from the console.log line. You had everything there, but removed most of the working code for some reason..
Please add the names.push(name); line to inside the loop.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.