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

122
Views
Create array dynamically with the name from another array - Javascript

I need to create arrays dynamically. Suppose I have an array

name = ['a','b','c']

each of this values will be an array with a fixed size. like

a = [null, null, null]
b = [null, null, null]
c = [null, null, null]

Afterwards, I want to access each array with the value of name array. Like

name[0] will represent the 'a' array.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

const name = ['a', 'b', 'c'];
const arraysAggregator = {};
const fixedSize = 3;

name.forEach(key => {
  arraysAggregator[key] = new Array(fixedSize);
  //fill the content you need here
});

//test 
// access to an array as per key
console.log(arraysAggregator['a'])

// if you want to receive array of arrays you can use
const arrayOfArray = [...Object.values(arraysAggregator)];

console.log(arrayOfArray);

about 4 years ago · Santiago Trujillo 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!