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

138
Vistas
Retrive the value from the object where value of key is pointing to different object

Lets say I have a object

obj1 : {
  "a" : 22
  "b" : 33
  "c" : 67
}

and obj2 as

obj2 : {
  x:"obj1.a" (string - path)
  y: "obj1.b" (string- path)
}

but when i do obj2.x I get obj1.a which is correct but I want 22, How do I do this? Or is there any npm package which takes care of this?

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

0

Ok, so you can use get logic when defining your object in order to achieve this.. basically get would call a function when the key is accessed and the value would be what that function returns

let obj1={
  "a" : 22,
  "b" : 33,
  "c" : 67
}

let obj2={
  get x(){
    return obj1.a
  },
  get y(){
    return obj1.b
  }
}

console.log([obj2.x,obj2.y]) //[22,33]
obj1.a++; obj1.b++ //changing obj1 to prove that it obj2 will change when obj 1 changes
console.log([obj2.x,obj2.y]) //[23,34]

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