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

166
Vistas
change object property value by other object property value Typescript

Hello I want to change a property value of an object by another property value of another object

I have two arrays:

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'}];

How can I set the value imageURL from arr2 in arr1 imageURL by id in Typescript?

pseudocode: If id in arr2 matches with id in arr1 set arr1.imageURL = arr2.imageURL

Info: I am not allowed to replace the entire object.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Assuming arr2 has only one value,

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

If arr2 has multiple values, you can use forEach in the same too

about 4 years ago · Juan Pablo Isaza Denunciar

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 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