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

202
Views
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 answers
Answer question

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 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!