I have the following scenario, and I would like to be able to use the array inside the event listener:
var array = []; array.push( { id:1, value:"1", desc:"abc" } ); button.addEventListener('click', function( array ){ alert( this.array.length ); });How do I reference the array from inside the Event Listener, as this code is not functional?
Thanks guys....
1 Answer
Accepted Answer
You are just doing a simple mistake here. as long as the eventListener are in the same block or in same scope you can do like this
var array = []; array.push( { id:1, value:"1", desc:"abc" } ); button.addEventListener('click', function( ){ alert( array.length ); });
Your Answer
Think you can help? Login to answer this question!