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

229
Vistas
How do i replace a value in an object with another updated value in an object if the id matches?

Currently, I am storing genre in the reducer.

const genre = {
    "0": {
        "id": 1912,
        "title": "Fiction",
        "name": "Greg"
    },
    "1": {
        "id": 1957,
        "title": "Non-Fiction",
        "name": "John"
    },
    "2": {
        "id": 1958,
        "title": "Literature",
        "name": "James"
    },
}

How do i check if the id in updatedGenre matches the id in genre, then i would update the title or name in genre with the updated title or name based on the id.

const updatedGenre = {
    "id": 1958,
    "title": "Literature & Poems",
    "name": "Leo"
}

Sample Output: (Example id: 1958)

const genre = {
    "0": {
        "id": 1912,
        "title": "Fiction",
        "name": "Greg"
    },
    "1": {
        "id": 1957,
        "title": "Non-Fiction",
        "name": "John"
    },
    "2": {
        "id": 1958,
        "title": "Literature & Poems",
        "name": "Leo"
    },
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should be able to accomplish this with an iteration through your object. See below:

for (const key in genre) {
   if (genre[key]["id"] === updatedGenre["id"]) { 
      genre[key]["title"] = updatedGenre["title"] 
   }
}
   

Let me know if it works, best of luck!

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