Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda