Assuming you are using wp_enqueue_script to load the .js, then use wp_localize_script to set the value of your key.
Another option is to use wp_add_inline_script instead of wp_localize_script
.
Assuming you are using wp_enqueue_script to load the .js, then use wp_localize_script to set the value of your key.
Another option is to use wp_add_inline_script instead of wp_localize_script
.