Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda