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

237
Views
Javascript Node.js get all the specific array value

This part of code only shows the first and second person in the database "Ban" status.

console.log("Banned0",res.data.data[0].banned); //display the first person banned status
console.log("Banned1",res.data.data[1].banned);  //display the second person banned status

enter image description here

I would like to console.log all 5 person banned status without repeatedly using console.log.

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

0

One possible solution, using Array.prototype.forEach:

res.data.data.forEach((data, idx) => console.log('Banned' + idx, data.banned));
about 4 years ago · Juan Pablo Isaza Report

0

If you find an array, you must looping the data, u can use this function

array.map(data => console.log(data));
or
array.forEach((data) => console.log(data));

Read this articles: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration?retiredLocale=id

about 4 years ago · Juan Pablo Isaza Report

0

You can use any kind of for loop to iterate over the data.

My suggestion is to either use a for of loop:

for (const dataItem of res.data.data) {
    console.log("Banned", dataItem.banned);
}

or a forEach loop on the array, which would also easily get you the index:

res.data.data.forEach((dataItem, index) => {
    console.log(`Banned ${index}`, dataItem.banned);
});
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!