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

143
Vistas
filter array into different array on the basis of fields

I have a array as follows:

[
  {
            "values": [
              {
                "title": "Status",
                "text": "closed"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "overdue"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "open"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "open"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "closed"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2022-01-29"
              }
            ]
    }
]

I want my final output in three arrays closedArray,openArray,dueArray. I want to traverse this array, go to status field, check status. if status is closed, then put element in closedArray, if overdue then put element in due array, if open put element in open array. If date in Timeline field passed the current date, then need to put that element in openArray. How can I do this?

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

0

Hey please check this out:

const results = {};
const array=[{values:[{title:"Status",text:"closed"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"overdue"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"open"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"open"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"closed"},{title:"Timeline",text:"2021-12-06 - 2022-01-29"}]}];


array.forEach(e => (
   new Date(e.values[1].text.split(" - ")[1]) > new Date() ? // check if date has passed
      results["open"]?.push(e) || (results["open"] = [e]) : // if yes -> add to open array
   results[e.values[0].text]?.push(e) || (results[e.values[0].text] = [e]) // else add to other key
));

const {open, closed, overdue} = results;
console.log("openArray", open);
console.log("closedArray", closed);
console.log("overdueArray", overdue);

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