Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
Texto mecanografiado - Crear objeto basado en otro

Tengo el siguiente objeto (esta es la respuesta del servicio):

 let contentArray = { "errorMessages":[ ], "output":[ { "id":1, "excecuteDate":"2022-02-04T13:34:20" }, { "id":2, "excecuteDate":"2022-02-04T12:04:20" }, { "id":3, "excecuteDate":"2022-02-01T11:23:34" }, { "id":4, "excecuteDate":"2022-01-14T10:30:54" }, { "id":5, "excecuteDate":"2021-11-03T10:20:43" } ] }

Basado en el objeto anterior, tengo que crear lo siguiente:

 { "2021":{ "11-November":{ "03/11/2021":[ "10:20:43" ] } }, "2022":{ "01_January":{ "14/01/2022":[ "10:30:54" ] }, "02_February":{ "01/02/2022":[ "11:23:34" ], "04/02/2022":[ "12:04:20", "13:34:20" ] } } }

Para poder pintar algo como esto en la pantalla:

ingrese la descripción de la imagen aquí

Actualicé la pregunta para ser más específica. Basado en lo anterior, tengo este código:

 let dateExecutionValue: Date; let i: number = 0; let tree = {}; while (i < this.contentArray.length) { dateExecutionValue = new Date(this.contentArray[i].excecuteDate); let year = dateExecutionValue.getFullYear(); tree[year] = {}; let auxYear = year; while (auxYear === year && i < this.contentArray.length) { let month = dateExecutionValue.getMonth() + 1; // here, now under the year property of the object, I want to create another month property (for each month associated with that year) i++; } }

¿Cómo podría hacerlo? Gracias,

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. Iterar a través de la respuesta
  2. Aplicar algo de lógica para transformar el valor devuelto en una fecha e insertar en una nueva propiedad
  3. Insertar en html / Manipulación DOM
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda