I am not sure I understand the question, but maybe this can be one of the approaches.
https://playground.jsreport.net/w/anon/PASAZy83h
Most of such things can be easily solved using handlebars. Here you can find detailed documentation
https://handlebarsjs.com/guide/
Also, there are tons of resources on StackOverflow so just google "handlebars ..."
Please try to share minimal playground demo when asking questions. Just like I did. Without specific noise around. This will help us to understand your question and provide the best answer.