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

143
Vistas
Jquery Object and Array implementation

I have an Object

let data =  {
        a: 1,
        b: 2,
        c: {
            abc: "ak",
            bcd: "gh",
            cfv: "ht"
        }
    }

then I have variables which I need to show with these object value

   let abc = "first 1", bcd="sec2", cfv="third3" , def="fourth 4", tdf = "fifth 5";

Now the Object will come in API call it can be any of these variable.

How can I match the variable name with the object data.c.(object key) and concatinate their value.

for example the output should be As we have (abc, bcd, cfv) as our object key then the output would be

first 1ak ==> that is the value of (abc + data.c["abc"])
sec2gh    ==> that is the value of (bcd + data.c["bcd"])
third3ht  ==> that is the value of (cfv + data.c["cfv"])

I tried using Object.keys() method so from this method we will get the object keys in array then how can I match with the variable name - Object.keys(data.c); ==> ["abc", "bcd", "cfv"] (After this how can I proceed to match the variable and show their values?)

Shall I loop throught the object that (data.c)?

Please help me giving some ideas to achieve this implementation. thank you

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

0

If it's possible for you to amend the format of your abc, bcd etc. variables to be the properties in an object, then this problem becomes trivial. You can use flatMap() to create a new array of the output values by linking the properties of the two target objects, like this:

let values = {
  abc: "first 1",
  bcd: "sec2",
  cfv: "third3",
  def: "fourth 4",
  tdf: "fifth 5"
}

let data = {
  a: 1,
  b: 2,
  c: {
    abc: "ak",
    bcd: "gh",
    cfv: "ht"
  }
}

let output = Object.keys(values).flatMap(k => data.c.hasOwnProperty(k) ? values[k] + data.c[k] : []);
console.log(output);

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