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

170
Views
Converting a function into an arrow

I have the following basic js function:

function copy_array(arr) {
    // copy array and return existing array
    const cp = [];
    for(let i=0; i < arr.length; i++)
        cp[i] = arr[i];
    return cp;
}

Is it possible to convert this into an arrow function, for example:

const copy_array2 = (arr) => {
   // ?
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simply:

const copy_array2 = (arr) => {
    const cp = [];
    for(let i=0; i < arr.length; i++)
        cp[i] = arr[i];
    return cp;

}

const arr = [1, 2, 3]
const copy = copy_array2(arr)

arr[0] = 5

console.log(copy)

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!