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

82
Vistas
Return a spread object doesn't update a property

I have the following code:

const createSpaces = () => {
  return Array(constants.SPACES)
    .fill(null)
    .map((_, index) => ({
      desk: index,
      isDeskAvailable: true,
      timeOccupied: 0,
    }));
};

and a function to update it:

 markDeskAvailable(deskRequested: number) {
      const occupiedDesk = spaces.find(
        (space) => space.desk === deskRequested
      );

      if (!occupiedDesk) {
        throw new Error("Desk does not exist.");
      }

     
      return {
          ...occupiedDesk,
          isDeskAvailable: true,
          timeOccupied: 0
      }
};

This doesn't throw an error, but my spaces array of objects doesn't update when I do:

const office = createSpaces();
carPark.markDeskAvailable(0);
console.log(office.getSpaces()); // Just returns the spaces

What am I doing wrong here? The object should have changed its properties.

about 4 years ago · Juan Pablo Isaza
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