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

211
Vistas
How to add multiple ids and content?

Javascript
In a constructor and I want to manipulate it and want to add as many ids and content as much as I want.

var groups = new vis.DataSet([
  { id: 1, content: "" },
  { id: 2, content: "" },
  { id: 3, content: "" },
  { id: 4, content: "" },
]);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I am not 100% sure what you're asking for, so here are two solutions.

As Insyri mentioned in the comments, you should utilize the spread syntax. You could do something along the lines of this:

var groups = [
  { id: 1, content: 'abc' },
  { id: 2, content: 'cba' },
  { id: 3, content: '123' },
  { id: 4, content: '321' },
];

class someClass {
  constructor(...data) {
    this.key = data;
  }
}

const test = new someClass(...groups);

console.log(test)

The output of the console log will look like this:

someClass {
  key: [
    { id: 1, content: 'abc' },
    { id: 2, content: 'cba' },
    { id: 3, content: '123' },
    { id: 4, content: '321' }
  ]
}

If you want all of the objects to have a unique key (of whatever you want), you can do this:

class otherClass {
  constructor(...data) {
    data.forEach(obj=>{
      this[obj.id] = obj
    })
  }
}

const test2 = new otherClass(...groups);

console.log(test2)

Output:

otherClass {
  '1': { id: 1, content: 'abc' },
  '2': { id: 2, content: 'cba' },
  '3': { id: 3, content: '123' },
  '4': { id: 4, content: '321' }
}
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