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

168
Views
How to split the array if the Array.length is higher than 5 in javascript
const array = [1...7]

so i have this array as u can see the length is 7, so i want the result like this

[1, 2, 3, 4, 5] and [6, 7]


same for the array below

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

the length is 11, therefore the result i want should be

[1, 2, 3, 4, 5] and [7, 8, 9, 10] and [11]

why 11 only? because i want to seperate array lengths by 5

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

0

I had written an splitter function that does the job:

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

function splitter ( arr, length = 5 ) {
  let result = [];
  let intermediateArray = [];
  arr.reverse().map( (el,index) => {
    intermediateArray.push(el);
   
    if (index % length === 0) {
      result.push(intermediateArray.reverse());
      intermediateArray = []
    }
  })
  return result.reverse();
}

console.log(splitter(array))

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!