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

203
Views
How to override object property value by index?

I have created an object that contains properties with empty values. I would like to access these properties by index and override their values. How can I do this ?

GetAllData: function(){
    var jobPayments = $("#table1 tbody tr");
    var jobPaymentsModels = [];
    jobPayments.each(function (idx, vl) {
        var jobPayment = {date:"",amount:0.0,method:"", reference:""};
        $(this).find("td input,select").each(function (idx, vl) {
            jobPayment[idx] = vl.value;
        });
        jobPaymentsModels.push(jobPayment);
    });
    return jobPaymentsModels;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Although object properties do have order now (which you'd need to use an "index" to access them), it's almost never a good idea to use that order, not least because its a bit complicated and depends on how the object is created.

Instead, I'd suggest having the name of the relevant object property on the input/select (if you don't already). Then you can use that name to set the property. Here I'm assuming you have name="date" etc. on the input/select elements:

var jobPayment = {date: "", amount: 0.0, method: "", reference: ""};
$(this).find("td input, select").each(function (idx, vl) {
    const value = vl.name === "amount" ? parseFloat(vl.value) : vl.value;
    jobPayment[vl.name] = vl.value;
});

Details on that jobPayment[vl.name] notation in this question's answers.

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!