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

197
Views
Passing the table in functions after pressing the button

Passing the table in functions after pressing the button. How can I get this effect with all the array options (.shift) I am getting the following message: app.js:13 Uncaught TypeError: arr.shift is not a function at HTMLButtonElement.b (app.js:13)

const btn = document.getElementById('id1');
btn.addEventListener('click', b)
function a() {
    const arr = [1, 2, 3 , 4];
    const btn = document.getElementById('id1');
    btn.addEventListener('click', b);
 }
 a()

 function b(arr) {
    arr.shift();
    console.log(arr);
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

By passing b in to the addEventListener function, it is being passed the event variable to the arr parameter. However, the event variable is not an array, so it does not have the array prototype functions. If you want to use the arr variable declared in a, you would need to use something like this:

function a() {
    const arr = [1, 2, 3 , 4];
    const btn = document.getElementById('id1');
    btn.addEventListener('click', (e)=>{b(arr)});
 }
 a()

Any event listener will always be passed an object describing the event.

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!