Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

394
Visualizações
How to select current month from a list of months with JavaScript?

I have a list of months in JSON, want to select the current month from the list in React Native.

Here is my list:

Month: [
  { value: "1", label: "JAN", key: "JAN" },
  { value: "2", label: "FEB", key: "FEB" },
  { value: "3", label: "MAR", key: "MAR" },
  { value: "4", label: "APRIL", key: "APRIL" },
  { value: "5", label: "MAY", key: "MAY" },
  { value: "6", label: "JUN", key: "JUN" },
  { value: "7", label: "JUL", key: "JUL" },
  { value: "8", label: "AUG", key: "AUG" },
  { value: "9", label: "SEP", key: "SEP" },
  { value: "10", label: "OCT", key: "OCT" },
  { value: "11", label: "NOV", key: "NOV" },
  { value: "12", label: "DEC", key: "DEC" }
];
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

By doing as below, you get the current month mapped to the one inside your array:

let Month = [
  { value: "1", label: "JAN", key: "JAN" },
  { value: "2", label: "FEB", key: "FEB" },
  { value: "3", label: "MAR", key: "MAR" },
  { value: "4", label: "APRIL", key: "APRIL" },
  { value: "5", label: "MAY", key: "MAY" },
  { value: "6", label: "JUN", key: "JUN" },
  { value: "7", label: "JUL", key: "JUL" },
  { value: "8", label: "AUG", key: "AUG" },
  { value: "9", label: "SEP", key: "SEP" },
  { value: "10", label: "OCT", key: "OCT" },
  { value: "11", label: "NOV", key: "NOV" },
  { value: "12", label: "DEC", key: "DEC" }
];

let currentMonth = Month[new Date().getMonth()];
console.log(currentMonth);

about 4 years ago · Juan Pablo Isaza Relatório

0

You can find the current month index using

const currentMonthIndex = new Date().getMonth() + 1

Month usually start from 0 so you have to add 1 Then you can filter through the array

const selectedMonth = months.find(m => m.value === currentMonthIndex)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda