Q:

How to generate an array of quarter numbers of a year along with year number based on current date using moment.js in node js?

I want to create an array of quarter numbers along with year number using current timestamp in node js.
For example, current quarter is, Q1 and year is, 2020. Now, I want to create an array like the following.
quarters = ['Q2-2019','Q3-2019','Q4-2019','Q1-2020']
In the above array, Q1 is of year 2020 and remaining 3 are from year 2019
Basically my requirement is to create array of quarters including present quarter number and past 3 quarter numbers along with year number.
Right now, am getting an array like, ['Q2','Q3','Q4','Q1'] by using the following code given by @Santhosh S. The code is,
let quarters = [ 0, 1, 2, 3 ].map(i => 
  moment().subtract(i, 'Q').format('[Q]Q')
);

console.log(quarters);

Is there anyway to generate this array?

A:

use moment().quarter(); to get current quarter. 
Edit: use subtract and format to Quarter. Sample code below

let format      = '[Q]Q';
let quarters = [
  moment().format(format),
  moment().subtract(1, 'Q').format(format),
  moment().subtract(2, 'Q').format(format),
  moment().subtract(3, 'Q').format(format)
];

console.log(quarters);
<script src="https://momentjs.com/downloads/moment.min.js"></script>

Or a more concise version:

let quarters = [ 0, 1, 2, 3 ].map(i => 
  moment().subtract(i, 'Q').format('[Q]Q')
);

console.log(quarters);
<script src="https://momentjs.com/downloads/moment.min.js"></script>

