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

245
Vistas
Navigating/Iterating in object as Interface to obtain key-value pair
export interface Worker {
  salary?: number;
  manager?: boolean;
  name?: string;
  hired?: Date;
}

const worker1: Worker = { salary: 5000, manager: true, name: "Bob", birth: new Date() };

I need to obtain all pairs of attributes as key - value.

for (const [key, value] of worker1????) {
    console.log("key: '" + key + "', value: " + value); // to do other needed operations
}

The output expected for this log Question is :

key: 'salary', value: 5000
key: 'manager', value: true
key: 'name', value: Bob
key: 'birth', value: xxxxx

How achieve that?

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

0

I think you just want the Object.entries() method?

for (const [key, value] of Object.entries(worker1)) {
    console.log("key: '" + key + "', value: " + value);
}
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