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

190
Vistas
How i can convert array of object into array then a unique count of array
const form = [
    {
        "_id": "61436aa8deef0390dcfdea79",
        "user": "613f92eb98da0c5facc1b4ca",
        "registerName": "Edwin",
        "email": "edwin@asng.space",
        "category": "Urusan Lain Lain",
        "title": " Ah Yong",
        "contactNumber": "0191231232",
    --> "time": "8am",
        "dateBooking": "2021-09-18",
        "icNumber": "860909-49-5851",
        "date": "2021-09-16T16:02:48.457Z",
        "__v": 0
    },
    {
        "_id": "61436ab8deef0390dcfdea7a",
        "user": "613f92eb98da0c5facc1b4ca",
        "registerName": "ESTSETS",
        "email": "123@gmail.com",
        "category": "Daftar Baru",
        "title": " Ah Yong",
        "contactNumber": "0149530130",
    --> "time": "8am",
        "dateBooking": "2021-09-18",
        "icNumber": "123123123123",
        "date": "2021-09-16T16:03:04.211Z",
        "__v": 0
    },
    {
        "_id": "61436b1894116c90f82170b9",
        "user": "613f92eb98da0c5facc1b4ca",
        "registerName": "Ah Yong",
        "email": "312@gmail.com",
        "category": "Pertanyaan",
        "title": " Ah Yong",
        "contactNumber": "0149530130",
   -->  "time": "9am]",
        "dateBooking": "2021-09-18",
        "icNumber": "123654",
        "date": "2021-09-16T16:04:40.962Z",
        "__v": 0
    }
]

How can i convert time inside the object into

uniqueCount = [8am,9am,10am,8am,9am,10am,8am,9am,10am,11am];

and count the frequency of each time in the array? I want to have a result like:

8am = 3
9am = 3
10am = 3
11am = 1

I'm not sure whether this will work cause I would like to filter each time got how many people to create an condition.

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

0

You can use Array#map to get an array of the time properties and then use Array#reduce to get an object with the frequencies.

const arr=[{_id:"61436aa8deef0390dcfdea79",user:"613f92eb98da0c5facc1b4ca",registerName:"Edwin",email:"edwin@asng.space",category:"Urusan Lain Lain",title:" Ah Yong",contactNumber:"0191231232",time:"8am",dateBooking:"2021-09-18",icNumber:"860909-49-5851",date:"2021-09-16T16:02:48.457Z",__v:0},{_id:"61436ab8deef0390dcfdea7a",user:"613f92eb98da0c5facc1b4ca",registerName:"ESTSETS",email:"123@gmail.com",category:"Daftar Baru",title:" Ah Yong",contactNumber:"0149530130",time:"8am",dateBooking:"2021-09-18",icNumber:"123123123123",date:"2021-09-16T16:03:04.211Z",__v:0},{_id:"61436b1894116c90f82170b9",user:"613f92eb98da0c5facc1b4ca",registerName:"Ah Yong",email:"312@gmail.com",category:"Pertanyaan",title:" Ah Yong",contactNumber:"0149530130",time:"9am",dateBooking:"2021-09-18",icNumber:"123654",date:"2021-09-16T16:04:40.962Z",__v:0}];
const res = arr.map(x => x.time).reduce((acc, curr)=>{
  acc[curr] = (acc[curr] || 0) + 1;
  return acc;
}, {});
console.log(res);

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