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

132
Views
Convery array of strings to array of objects - every 3rd index

I'm trying to convert an array of strings to an array of objects after every 3rd index.

Input:

let tee = [
  'Blue',             '130',
  '70.8',             'Blue',
  '128',              '708',
  'White',            '124',
  '68.2'
]

Code:

            function fillTeeBoxes(holesAmount) {
            for (let i = 0; i < holesAmount.length; i++) {
                let teeBox = ['tee', 'slope', 'rating']
                let holeData = {};
                for (let j = 0; j < 3; j++) {
                    holeData[teeBox[j]] = parseInt(getTeeBoxes[i]) || getTeeBoxes[i]
                    i++
                };
                teeBoxes.push(holeData)
            };
        };

Expected Output:

    tee = [
      {tee: 'Blue', slope: 130, handicap: 70.8}
      {tee: 'Blue', slope: 128, handicap: 70.8}
      {tee: 'White', slope: 124, handicap: 68.2}
    ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

We can use a for loop and iterate in steps of 3:

let tee = [
  'Blue',             '130',
  '70.8',             'Blue',
  '128',              '708',
  'White',            '124',
  '68.2'
];
var output = [];

for (var i=0; i < tee.length; i+=3) {
    var obj = {tee:tee[i], slope:tee[i+1], handicap:tee[i+2]};
    output.push(obj);
}

console.log(output);

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!