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

101
Views
Usar el valor almacenado en la variable para actualizar una propiedad de objeto

Tengo una variable de javascript, llámela temp, que contiene la entrada de valor de un usuario. Por ejemplo,

 const temp=10

Quiero actualizar una propiedad de objeto a este valor variable.

Por ejemplo, quiero cambiar

 var data = [ { "1": "1.5", "2": "2", "subject_input": "null", "entry": 1 } ]

a

 var data = [ { "1": "1.5", "2": "2", "subject_input": value of the javascript variable 'temp', "entry": 1 } ]

Intenté simplemente incluir la variable de esta manera:

 var data = [ { "1": "1.5", "2": "2", "subject_input": "temp", "entry": 1 } ]

y esto

 var data = [ { "1": "1.5", "2": "2", "subject_input": temp, "entry": 1 } ]

y tampoco funcionó. ¿Hay una forma fácil de hacer esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 var data = [{"1":"1.5","2":"2","subject_input":"null","entry":1}] const temp = "temp data"; data = data.map(o => ({...o, subject_input: temp})); console.log(data); //or directly assigning temp to subject_input var data2 = [ { "1":"1.5", "2":"2", "subject_input":temp, "entry":1 } ]; console.log(data2);

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!