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

318
Views
Why do an unexpected token "return" with forEach?

Why doesn't ara return the unxpected token error, instead of 23 added to each value in the array?

        var aras = [1,2,3,4,5]
        let ara = aras.forEach(item => item + 23);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Array.forEach doesnot return any value. So the value for ara in your statement will be undefined.

Array.forEach just loops through each element in an array, and perform an action. Here your action is item + 23, but it doesnot update anywhere.

If you want to genereate a new array from an existing one by making some changes to each element in the array, use Array.map

var aras = [1,2,3,4,5]
let ara = aras.map(item => item + 23);
console.log(ara);

about 4 years ago · Juan Pablo Isaza Report

0

forEach does return undefined. to return new array use map.

var aras = [1,2,3,4,5]
let ara = aras.map(item => item + 23);
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!