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

122
Views
Able to log array in console, but can't loop through it

Running into a problem. In react I'm grabbing data from a json api. Everything worked fine until I tried to display it. Except, I'm able to log it on the console.

What the console logs:

pic

<ul role="list" className="divide-y divide-gray-200 dark:divide-gray-700">
{username !== "null" && leaderlist.length > 2 && console.log(leaderlist) && leaderlist.map((leader, index) =>
       <li className="py-3 sm:py-4 text-white">
           Log 
        </li>
      )}
     <li className="py-3 sm:py-4 text-white">
         list length {leaderlist.length} 
     </li>
   </ul>

What it displays:

enter image description here

The code that sets

const [leaderlist, setleaderlist] = React.useState([]);
fetch(`${baseurl}/allusers`)
     .then(res => res.json())
     .then(data => {setleaderlist(data); console.log(data)})
     .catch(err => console.log(err));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

username !== "null" && leaderlist.length > 2 && console.log(leaderlist) && leaderlist.map((leader, index)

console.log(leaderlist) does not have a return value and thus leaderlist.map((leader, index) ...) does not run since you're using &&. You need to remove the console.log statement or use ; instead of &&.

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!