• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

163
Views
¿Cómo reemplazo un valor en un objeto con otro valor actualizado en un objeto si la identificación coincide?

Actualmente, estoy almacenando el género en el reductor.

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

¿Cómo verifico si la identificación en el género actualizado coincide con la identificación en el género ? Entonces actualizaría el título o el nombre en el género con el título o el nombre actualizado según la identificación.

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

Salida de muestra: (Id. de ejemplo: 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 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debería poder lograr esto con una iteración a través de su objeto. Vea abajo:

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

Avísame si funciona, ¡mucha suerte!

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error