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

195
Views
¿Cómo anular el valor de la propiedad del objeto por índice?

He creado un objeto que contiene propiedades con valores vacíos. Me gustaría acceder a estas propiedades por índice y anular sus valores. Cómo puedo hacer esto ?

 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

Aunque las propiedades de los objetos ahora tienen un orden (para lo cual necesitaría usar un "índice" para acceder a ellas), casi nunca es una buena idea usar ese orden, sobre todo porque es un poco complicado y depende de cómo se crea el objeto. .

En cambio, sugeriría tener el nombre de la propiedad del objeto relevante en la input / select (si aún no lo tiene). Luego puede usar ese nombre para establecer la propiedad. Aquí asumo que tiene name="date" , etc. en los elementos de input / select :

 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; });

Detalles sobre esa jobPayment[vl.name] en las respuestas de esta pregunta .

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!