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

110
Vistas
Need to check array of object in React.js

I have a bunch of objects inside an array and I have to check status of each object and return a single value for each array.

(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {projId: 1, task: 'task 1', status: 'completed'}
1: {projId: 1, task: 'task 2', status: 'completed'}
2: {projId: 1, task: 'task 3', status: 'completed'}
3: {projId: 1, task: 'task 4', status: 'completed'}
4: {projId: 1, task: 'task 5', status: 'completed'}
5: {projId: 1, task: 'task 6', status: 'completed'}
6: {projId: 1, task: 'task 7', status: 'completed'}
7: {projId: 1, task: 'task 8', status: 'completed'}
8: {projId: 1, task: 'task 9', status: 'completed'}
9: {projId: 1, task: 'task 10', status: 'completed'}

Need to check the status, and if it is completed for the whole array then return competed else return in progress. The code I tried is given below, but that returns for each object in array.

{GroupedData[key].map(status => ((status.status === "completed")? "Completed" : "In Progress"))} 

And I am writing this inside the return of export function in React.js

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

0

.map() method is used to change values in a given array and returns that new modified array. In your case, your code changes each value in your array to completed / in progress depending on the status of the object.

In your case, I think that using .some() or .every() will be the best way to go about this. In the code below you are checking that every project has status completed and if that returns true it assigns 'completed' to result, if not it assigns 'in progress'

const result = data.every((project) => project.status === 'completed') ? 'completed' : 'in progress';
about 4 years ago · Juan Pablo Isaza Denunciar

0

try this:

yourArrayObject.every((itemObject) => itemObject.status === 'completed') ? 'Completed' : 'In Progress';
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