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

220
Vistas
How can I create a list of objects dinamically in JavaScript?

I'm trying to create an object then put it into an array. But (I guess) when I create a new object the objects inside of the array is getting modified as well, so all the array is getting the same object. Is something like the code below. How can I make an array of differents objects?

var randomCode = []
var fligthRange = []
var maintenanceArr = []
var results = {ID: '', range: '', maintenance: ''} //the object
var finalResults = [] //the array of objects
var counter = 0

function send(){     //this function is called when a button is clicked on html
  results.ID = randomCode[counter]
  results.range = fligthRange[counter]
  results.maintenance = maintenanceArr[counter]
  finalResults[counter] = results
  counter++
}

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

0

Just build the object literal in the function itself:

function send(){
  finalResults[counter] = {
    ID: randomCode[counter], 
    range: fligthRange[counter], 
    maintenance: maintenanceArr[counter]
  }
  counter++
}

You will get a new instance added to the array every time the function is called.

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