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

221
Views
Updating table depending on dynamic keys of object

Here myObject is an object and I want to update my table depending upon the number of keys myObject contains. The number of keys in myObject can be dynamic how do I update the table in that case?

var myObject ={
   x1 : 0,
   x2 :1
}

var stmt =""UPDATE tb_data SET x1 = ?, x2 = ?....xn =?";
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try using Object.keys(myObject).forEach to loop through each of your objects, building up the string you need each time.

var myObject ={
       x1 : 0,
       x2 :1
    }

    var stmnt = '';

    Object.keys(myObject).forEach((val) => {
      stmnt += val;
    })
over 4 years ago · Santiago Trujillo Report

0

Improving on jsw324's answer

var myObject ={
   x1 : 0,
   x2 :1
}

let stmt ='UPDATE tb_data SET ';

Object.keys(myObject).forEach((key)=>{
    const val = myObject[key];
    stmt += `${key} = ${val}, `;
})

stmt = stmt.splitOnLast(',')[0]+';'
//Stmt = "UPDATE tb_data SET x1=0, x2=1;"
over 4 years ago · Santiago Trujillo 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!