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

151
Views
I want rows to column with type wise in JavaScript. is it possible?

I have a Array in multiple type e.g Time-In or Time-Out , Break-in ,Break-out etc. here is list

const data = 
  [ { 
    , entryDateTime             : '02:28'
    , activityTypeId            : 'Time In'
    , comments                  : 'dgdfgdfg'
    , isLeave                   : ''
    } 
  , { timeSheetDetailActivityId : 0
    , timeSheetDailyActivityId  : 0
    , entryDateTime             : '03:28'
    , activityTypeId            : 'Time Out'
    , comments                  : '2323'
    , isLeave                   : ''
    } 
  , { 
    , entryDateTime             : '04:28'
    , activityTypeId            : 'Break In'
    , comments                  : '2323'
    , isLeave                   : ''
    } 
  , { timeSheetDetailActivityId : 0
    , timeSheetDailyActivityId  : 0
    , entryDateTime             : '05:28'
    , activityTypeId            : 'Break Out'
    , comments                  : '2323'
    , isLeave                   : ''
    } 
  , { 
    , entryDateTime             : '06:28'
    , activityTypeId            : 'Time In'
    , comments                  : '2323'
    , isLeave                   : ''
    } 
  , {
    , entryDateTime             : '07:28'
    , activityTypeId            : 'Time Out'
    , comments                  : '232323'
    , isLeave                   : ''
    } 
  ] 

i want above list to like this

[ {
  , Time In                  : '02:28'
  , Time Out                 : '03:28'
  , Break In                 : '02:28'
  , Break Out                : '03:28'
  } 
, { 
  , Time In                  : '06:28'
  , Time Out                 : '08:28'
  , Break In                 : '02:28'
  , Break Out                : '03:28'
  } 
]

how is possible?

i ll be thanks full to all am stuck from 2 days Please help me or give some time on it. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sure, piece of cake.

Build an object that keeps track of your data per activity ID, then read it.

const groupedData = {};
data.forEach(({ timeSheetDailyActivityId, activityTypeId, entryDateTime }) => {
  // Retrieve group object from `groupedData`,
  // initialize one (assigning it back) if it doesn't yet exist.
  const group =
    groupedData[timeSheetDailyActivityId] ||
    (groupedData[timeSheetDailyActivityId] = { timeSheetDailyActivityId });
  // Add the activity->datetime mapping to the group.
  group[activityTypeId] = entryDateTime;
});
// Since `groupedData` is an object and we want an array, use `Object.values`.
console.log(Object.values(groupedData));

This prints out e.g. (after changing the example input data a bit so there are multiple dailyIds):

[
  {
    timeSheetDailyActivityId: 0,
    'Time In': '02:28',
    'Time Out': '03:28',
    'Break In': '04:28',
    'Break Out': '05:28'
  },
  {
    timeSheetDailyActivityId: 1,
    'Time In': '06:28',
    'Time Out': '07:28'
  }
]
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!