Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
Using value stored in variable to update an object property

I have a javascript variable, call it temp, that is holding value input by a user. For example,

const temp=10

I want to update an object property to this variable value.

For example, I want to change

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

to

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

I've tried just including the variable like this:

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

and this

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

and neither worked. Is there an easy way to do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda