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

110
Views
Why is this react array not being overwritten after each loop?

I have this piece of code which calls one of two functions to return some JSX which is then added to an array to be displayed later in the function. The problem that I am having is that on each loop through the inputs array in subsections is not being overwritten and as such the inputs for other subsections are being added to the final array multiple times.

Any advice or direction on where to look to solve this problem would be greatly appreciated.

// Subsections
for (let i = 0; i < pageComponent['subsections'].length; i++) {
    let subsectionComponent = pageComponent['subsections'][i];
    let inputs = [];

    // Inputs
    for (let k = 0; k < subsectionComponent['questions'].length; k++) {
        let questionComponent = subsectionComponent['questions'][k]
        if (questionComponent['type'] === 'TextArea') {
            this[inputs].push(this.addTextArea(questionComponent));
        } else {
            this[inputs].push(this.addInput(questionComponent));
        }
    }
    subsectionInputs.push(<div key={i+"_subgroup_div"} className="form-group row">
        <h3 style={{margin: 15}}>{subsectionComponent[0]}</h3>
        {this[inputs]}
    </div>);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're referencing this[inputs] when I think you just intend to reference inputs directly.

if (questionComponent['type'] === 'TextArea') {
    inputs.push(this.addTextArea(questionComponent));
} else {
    inputs.push(this.addInput(questionComponent));
}

And here:

subsectionInputs.push(<div key={i+"_subgroup_div"} className="form-group row">
    <h3 style={{margin: 15}}>{subsectionComponent[0]}</h3>
    {inputs}
</div>);
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!