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

186
Views
JS - Repeat array items n times on n position?

I have entered the array in the format :

let in = [{name: "Milos", repeat: null},{name: "Milos1", repeat: 2},{name: "Milos2", repeat: null},{name: "Milos3", repeat: 4}, .... ];

What is key here, the key is the repeat property.

What that means,

If any item in the array has repeat property, that item must be repeatable in the array, which means, will be placed in position n, with n repeat times, array what is expected as result is :

let out = [
{name: "Milos", repeat: null},
{name: "Milos1", repeat: 2},
{name: "Milos2", repeat: null},
{name: "Milos1", repeat: 2},
{name: "Milos3", repeat: 4}, ...., 
{name: "Milos1", repeat: 2}, ...  
{name: "Milos3", repeat: 4}, ..., 
{name: "Milos1", repeat: 2}, ... 
{name: "Milos3", repeat: 4}, ...];

Note: Dots means items with repeat property null.

Limitation, I don't want to expand the array is there no more space for that.

about 4 years ago · Juan Pablo Isaza
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!