Can anyone assist me with the following code snippet for formatting the current month?
var monthNames = ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'];
I have implemented the following logic to achieve the desired month format:
var formatter = new Intl.DateTimeFormat("pt-BR", { month: "short" }),
month1 = formatter.format(new Date()) ;
var posicao = monthNames.indexOf(month1);
var mesesSelecionados = monthNames.slice(posicao, 12);
var mesesSelecionadosJson = {};
var arrayteste=[];
for ( i =0 ; i< mesesSelecionados.length; i++ ){
var teste = mesesSelecionados[i].toString();
mesesSelecionadosJson = JSON.stringify({ Mes : mesesSelecionados[i]}, null );
arrayteste.push(mesesSelecionadosJson);
console.log(arrayteste);
console.log(mesesSelecionadosJson );
};
I am aiming to obtain this output:
[{Mes:"abr"}, {Mes:"mai"}...]
(with all values in array)
If you can provide assistance, it would be greatly appreciated. Thank you!