I ran into a tricky problem about how to use custom javascript to get inventory in the background

I want to implement the function of a product in shopify to set different copy content in the front end according to the background inventory number. Can I use custom javascript to achieve this or what other methods?

If possible, please tell me some ways, I would appreciate it very much