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

75
Vistas
Add nested object properties to the main object

I have a response from an api call which is an array of Objects. I want to modify every object by removing the nested object 'company' and nested it directly to the main object. Is there a way to do that with a fast way ?

{
    "ip": "127.0.0.1",
    "hostname": "test.compute.amazonaws.com",
    "city": "São Paulo",
    "region": "São Paulo",
    "country": "Brazil",
    "loc": "-33.5375,-36.31",
    "org": "AS16509 Amazon.com, Inc.",
    "postal": "01000-000",
    "timezone": "America/Sao_Paulo",
    "company": {
      "name": "Amazon Data Services Brazil",
      "domain": "amazon.com",
      "type": "hosting"
    },
    "countryCode": "BR"
}

I want to change the json to this

{
    "ip": "127.0.0.1",
    "hostname": "test.compute.amazonaws.com",
    "city": "São Paulo",
    "region": "São Paulo",
    "country": "Brazil",
    "loc": "-33.5375,-36.31",
    "org": "AS16509 Amazon.com, Inc.",
    "postal": "01000-000",
    "timezone": "America/Sao_Paulo",
    "name": "Amazon Data Services Brazil",
    "domain": "amazon.com",
    "type": "hosting"
    "countryCode": "BR"
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I have used this function but I am checking if there's a faster method.

const formatObj = (obj) =>{
  obj.name = obj.company.name;
  obj.domain = obj.company.domain;
  obj.type = obj.company.type;
  delete obj.company
  return obj
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

var newList = listFromAPI.map((object) => {
delete object.company
return {...object};
});

here newList will have all the list of objects without company property

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