jQuery/JavaScript/React - Access variable within nested loop

Danny Santos Source

I'm attempting to loop through a group of elements and then loop through a bunch of values. For some reason I can't access the element within the second loop, despite the fact that I have declared it outside of the loop:

populateSelect2Filters(key) {
  var _this = this

  $(`#multi-filter-${key}`).find('option').each(function(index, element){
    var el = element;

    _this.refs.table.filter.currentFilter[`${key}`].value.forEach(function(simon){
      // el is not defined
    })
  })

  $(`#multi-filter-${key}`).trigger("change")  
}

It is showing as an Uncaught ReferenceError: el is not defined. It's my understanding that this should be available?

Thanks

javascriptjqueryreactjs

Answers

comments powered by Disqus