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

305
Vistas
How do i use a field of a json ojected to find another field of a different json object? (Javascript)

Basically i have a Get request that returns me a response with multiple json objects. I need to get a specific json object based on his name, manipulate that name and find the id of another object based on that modified name (in javascript).
Example:

  • I have a json with name: " XXXX Published", id: "1".
  • I need to get the name, change it to "XXXX Restricted" and find what is the id of the object with that name.

Can anyone give me a code snippet from which to work my way up?
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've assumed the response format in this response, let me know if it's not correct.

    const response = [
        {id: 1, name: "XXXX Published"}, 
        {id: 2, name: "XXXX Restricted"}, 
        {id: 3, name: "h3"}
    ]

    function replaceName(findName, name) {
        const index = response.findIndex(i => i.name === findName)
        if(index !== -1) {
            response[index].name = name;
        }
    }

    const oldName = "XXXX Published";
    const newName = 'XXXX Restricted'

    // This is the id that already has the new name
    const originalId = response.find(i => i.name === newName)?.id;

    // This mutates the response and changes the name
    replaceName(oldName, newName)
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