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

225
Views
Can we create arrays with for loop, without square bracket in javascript

Im new at javascript. Please help me.

Can we create arrays with for loop, without square bracket. Like :

var ar0 = num0
var ar1 = num1
.
.
var ar"i" = num"i"

i cant define like that :

for (i=0;i<5;i++){

var (ar+i) = num+i

}

i know this isnt array but i want create a lot like this. i have to use "for loop"

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use something like this:

 let result={};
    for (let i=0;i<5;i++){
        result["ar"+i]= `num${i}`;
    }
    console.log(result);

The result will be something like this:

{ ar0: 'num0', ar1: 'num1', ar2: 'num2', ar3: 'num3', ar4: 'num4' }

I hope that's what you are looking for.

about 4 years ago · Juan Pablo Isaza Report

0

I only see that as a solution :

let ar = Array.from({length:5},(_,i)=>`num${i}`)
about 4 years ago · Juan Pablo Isaza Report

0

Use eval built-in function :

for (i=0;i<5;i++){
    eval("var " "ar"+i + "= num+"i)
}
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!