Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
cambiar el valor de la propiedad del objeto por otro valor de la propiedad del objeto

Hola quiero cambiar un valor de propiedad de un objeto por otro valor de propiedad de otro objeto

Tengo dos matrices:

 let arr1 = [{id:1, name:'test user', imageURL:''}, {id:1, name:'test user', imageURL:''}, {id:1, name:'test user 3', imageURL:''}]; let arr2 = [{id:1, name:'test user', imageURL:'abcdefghijklmnop'}];

¿Cómo puedo establecer el valor imageURL de arr2 en arr1 imageURL por id en Typescript?

pseudocódigo: si la identificación en arr2 coincide con la identificación en arr1, establezca arr1.imageURL = arr2.imageURL

Información: No tengo permitido reemplazar el objeto completo.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Suponiendo que arr2 tiene un solo valor,

 this.arr1.forEach((item) => { if(item.id == this.arr2[0].id) { item[imageUrl] = this.arr2[0].imageUrl } })

Si arr2 tiene varios valores, también puede usar forEach en el mismo

about 4 years ago · Juan Pablo Isaza Report

0

 let arr1 = [{id:1, name:'test user', imageURL:''}, {id:1, name:'test user', imageURL:''}, {id:1, name:'test user 3', imageURL:''}]; let arr2 = [{id:1, name:'test user', imageURL:'abcdefghijklmnop'}]; function setUrl(arr1, arr2, id) { let obj = arr2.find(prop => prop.id == id) if(!obj) return null; let response = arr1.map(prop => { if(prop.id === id) { prop.imageURL = obj.imageURL } return prop }) return response } let result = setUrl(arr1, arr2, 1) console.log(result)

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!