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

145
Views
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 answers
Answer question

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