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

175
Views
Return Multiple things in a map function - react/Javscript

What would be the most efficient way to return multiple things in a .map function. For example, 2 separate console.log statements?

For example: This works just fine:

 return (
    <div className="App">
      {mycataobjects.map((myobject) => console.log(myobject.name))}
    </div>
  );

However, how would I add another console.log to this map, so that for each object in the array I get the phrase "Hello"

I tried the below but it does not work. It only prints "Hello" once. I want it printed for every object in the my.object array. What would be the best way to do this?

 return (
    <div className="App">
      {mycataobjects.map(
        (myobject) => console.log(myobject.name),
        console.log("Hello")
      )}
    </div>
  );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are really interested in the return values you could return a tuple kind of type and then flatten the array:

const arr = mycataobjects.map(item => [1, 2]);
const values = arr.flat();

However in your example if you just want to call console.log twice you'd need to add braces to your arrow function body:

mycataobjects.map(
  (myobject) => {
    console.log(myobject.name);
    console.log("Hello");
  }
);

Note that console.log is a void function so would just return undefined. Trying to grab its return value is not all that useful here.

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!