As described in this answer to a question about using dynamic variable names in javascript, all variables declared in the global context (outside of a function context), can be accessed as properties of the Global object. And because they're accessible as properties, you can use concatenation within bracket notation.
It's important to point out that the examples given in the answer above are for javascript that runs in the browser. The Global object for javascript in browsers is the window
object.
However, Pug runs in Node—not the browser. This answer to a different question about What is the node.js equivalent of window[“myvar”] = value? notes that the Global object in Node is global
.
So you should be able to do something like this in Pug:
.Contents
- for(var i = 1; i < length; i++)
- let qa = global['t' + i]
.QuestionFrame= qa.FAQ_QUESTION
.AnswerFrame= qa.FAQ_DESCRIPTION