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

162
Visualizações
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 Respostas
Responde à pergunta

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 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