Google and other search engine used to crawl/read source code from top to bottom. They didn't resolve or see the output of JavaScript code before. But as the requirements of user side Javascript is increasing, the support for this is added in google bots.
Google and other search engine crawlers read source code and process the Javascript dynamic content. Which means google will be able to understand your dynamic content that is loaded by Javascript.
Conclusion: You are good to go with Javascript dynamic content loading.
The solution to this is, you can use the backend language to load the alt and title tags dynamically example PHP.