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

106
Vistas
Check if object haves any nested objects and get its value

I have a sequence of JSON objects coming from a post request

{
  "labels": {
     "name": "Toma/Dyrskuvegen5/360.001/Avkasttemperatur"
  }
}

In some sequences the labels are empty (in which case should return false), in some, they are not. Also in some sequences the

labels.name

will be some other random key name, for example:

labels.room_number

My task is to identify if there is any key under labels and set two strings, one with the key name, and the other with the key-value example from above:

n = "name"

v = "Toma/Dyrskuvegen5/360.001/Avkasttemperatur"

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

0

You can use Object.entries to do this. It returns an array of a given object's [key, value] pairs

let incoming = {"labels":
    {"name":
    "Toma/Dyrskuvegen5/360.001/Avkasttemperatur"}};
    let incoming2 = {"labels":
    {"age":
    "22"}};
     let incoming3 = {"labels":
    {}};
    
let getThis = (incoming) => {
  let entries = Object.entries(incoming.labels);
  if(entries.length > 0){
  [s,v] = Object.entries(incoming.labels)[0];
  console.log(s,v);
  }
  return false;
};
getThis(incoming3);
getThis(incoming);
getThis(incoming2);

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