Google showing static title instead of dynamically set javascript title

Basically, lets say I have set my title using HTML to "Something – Example", and with Javascript I change the title to "Apple – Example". When I google my website (after waiting for it to update) or the link gets embedded on things such as twitter or discord, it shows the static "Something – Example" title instead of the new title.