Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!