If you’re seriously concerned about security, your idea will not help. Someone could put a checkpoint in your code where you’re getting the key and look at it that way.
The only way to keep a key secure in a web app is to never let it get to the web app. You’ll need to do the operation which required the secret key on a server, then send the results to the web app.