Within my Express route, I am retrieving a collection of entries from a MySQL database. These entries consist of words and associated line numbers that require the printing of all words on the same line together with a line break.
word | section
----------------
Lorem | 1
ipsum | 1
dolor | 1
sit | 2
amet | 2
Utilizing doT.js as my templating engine, my objective is to display this data as follows:
Lorem ipsum dolor
sit amet
As I iterate through the array of results from MySQL, I aim to print out each word. However, I am currently struggling to compare the line number of the current index with that of the previous one. My initial thought is to establish a variable for the current line and compare it to the preceding line. If they differ, then I can introduce a <br>
tag. Yet, I am encountering difficulties in implementing this solution.
Do I need to resort to using a helper method? If so, could someone direct me to a reliable tutorial? Alternatively, are there simpler methods to achieve this task?