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

183
Visualizações
Trying to get full results using DayJs

I'm trying to get the full results of this code execution, Right now what I get is only the date's of all values, but I need it so that all columns are displayed, so name and date. Can anyone help?

const result = [
    { id: 1, name: 'Tom', date: '2022-05-17T22:00:00.000Z' },
    { id: 2, name: 'Joe', date: '2022-05-12T22:00:00.000Z' },
    { id: 3, name: 'Frederiko', date: '2022-05-23T22:00:00.000Z' },
    { id: 4, name: 'John', date: null },
    { id: 5, name: 'Boer', date: '2022-05-23T22:00:00.000Z' }
  ]
  
let time = dayjs().format('YYYY-MM-DD')
let eyy = result.filter(item1 => !result.find(item2 => item1.name == item2.name && dayjs(item2.date).format('YYYY-MM-DD') == time))

console.log(eyy);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The result.filter method can be simplified by removing the use of result.find, for example...

const result = [
    { id: 1, name: 'Tom', date: '2022-05-17T22:00:00.000Z' },
    { id: 2, name: 'Joe', date: '2022-05-12T22:00:00.000Z' },
    { id: 3, name: 'Frederiko', date: '2022-05-23T22:00:00.000Z' },
    { id: 4, name: 'John', date: null },
    { id: 5, name: 'Boer', date: '2022-05-23T22:00:00.000Z' }
  ]
  
let time = dayjs().format('YYYY-MM-DD')
let eyy = result.filter(item => dayjs(item.date).format('YYYY-MM-DD') === time)

console.log(eyy);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>

It's probably worth noting that depending where you are in the world the above will most likely not return anything because there are no dates matching today's date (May 24th).


From your comments it appears you want to modify the structure of the filtered results. To do this you can use the .map() method...

const result = [
    { id: 1, name: 'Tom', date: '2022-05-17T22:00:00.000Z' },
    { id: 2, name: 'Joe', date: '2022-05-12T22:00:00.000Z' },
    { id: 3, name: 'Frederiko', date: '2022-05-23T22:00:00.000Z' },
    { id: 4, name: 'John', date: null },
    { id: 5, name: 'Boer', date: '2022-05-24T22:00:00.000Z' }
  ];
  
let time = dayjs().format('YYYY-MM-DD');
let eyy = result.map(item => {
  return {
    name: item.name,
    date: dayjs(item.date).format('YYYY-MM-DD')
  };
});
    eyy = eyy.filter(item => item.date === time);
    

console.log(eyy);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>

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