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

139
Views
Javascript: How to access the current index value inside an array stored function

If a function is stored in an array item, how can I gain access of the array's current index value inside the function?
For example, how can I set my function in order to get results similar to this?

arr['hello'](); // function returns 'hello'
arr['world'](); // function returns 'world'
arr[123]() // function returns 123
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Unless you know in advance which specific properties will be used, you'll need a Proxy.

const prox = new Proxy(
  {},
  {
    get(_, prop) {
      return () => prop;
    }
  }
);

console.log(prox[123]());
console.log(prox.hello());    
console.log(prox['world']());

Since you have some non-numeric properties, you shouldn't use an array.

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!