Not Sure if you have been moved SharePoint online to Modern sites and Classic Sites. Below are the approaches to use Custom JS.
With Modern Sharepoint Site Pages:
With Classic Sharepoint Site Pages:
when you are using classic Sharepoint pages on the Team site then you should enable custom scripts from Sharepoint Admin Center in your tenant and use Content editor OR Script editor web part.
I hope this solution should work for you.
I agree with Sajid Khan.
According to my research, SharePoint Online does not support integrating Custom JS code directly.
- On the Modern experience: You can use modern script editor web part, ex: react-script-editor
- On the Classic experience: You can use Content Editor web part or Script Editor web part.