Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda