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

67
Views
loop through list from backend

I have list from backend. I want to loop through all the elements of this list and hide the button if it has no status 6.

response

Returning from the response in the incoming list. It won't always be like this. It can come in 7 elements.

policyInstallmentDtoList: Array(1)
 0:
 amount: 291
 currency: "TRY"
 date: "10-02-2022"
 installmentNumber: 1
 status: "3"

I'm trying to loop through the list here.

useEffect(() => {
 if (paymentInfoData?.policyInstallmentDtoList?.forEach((e) => e['status'] !== '6')) {
   setHiddenControlButtonClass('hidden');
 }
}

html

<div className={hiddenControlButtonClass}>
  <AS.Button variant="outlined" onClick={handlePayment}>
    Devam
  </AS.Button>
</div>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use Array.some

It's a built-in method in JS's array prototype which returns a boolean value that represents whether or not at-least a single member in the array answers your condition.

useEffect(() => {
 if (!paymentInfoData?.policyInstallmentDtoList?.some(e => e.['status'] === '6') {
   setHiddenControlButtonClass('hidden');
 }
}

This should work just fine and only set the state once,
which is better for performance.

about 4 years ago · Juan Pablo Isaza Report

0

You don't need to put the forEach method in an if statement.

useEffect(() => {
  paymentInfoData?.policyInstallmentDtoList?.forEach((e) => {
    if (e.status !== '6') {
      setHiddenControlButtonClass('hidden');
    }
  }
}
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!