When I saw your script of your shared Google Apps Script project, in that case, how about the following modification? In this case, please modify the function of displayTable() at the HTML & Javascript side as follows.
From:
function displayTable(ar) {
To:
function displayTable(ar) {
ar = ar.splice(-12); // <--- Added
- In your question, the users cannot directly see your script. So, I explain a little about this modification. In your script, the function is
displayTable is called after GetRecords at Google Apps Script side was called, when "Login" button is clicked. In this case, the values from GetRecords is the 2 dimensional array. In this answer, the value you expect is retrieved from this array by ar = ar.splice(-12).
Reference:
Added:
From your following replying,
Bro if I am not mistaken, it will only minus 12 rows right. In the AppScript right every year new 12 rows ( which means in 2022 new rows will be added from January 2022 until December 2022). So this logic will be a problem later bro. Hope you will me in this bro. Thank you bro.
In this case, how about the following modification?
From:
function displayTable(ar) {
To:
function displayTable(ar) {
ar = ar.sort((a, b) => new Date(a).getTime() > new Date(b).getTime() ? -1 : 1).splice(-12); // <--- Added
In this case, the last 12 months are retrieved from ar.
If you want to retrieve the 12 months as the descending order, how about the following script?
ar = ar.sort((a, b) => new Date(a).getTime() > new Date(b).getTime() ? 1 : -1).splice(0, 12);