0

I'm uploading a file using Papa Parse and having trouble assigning the let data variable within complete. The data variable returns undefined. Can someone please explain what I'm doing wrong here?

handleCSVInputChange(event) {
  event.preventDefault();
  let data;

  const file = event.target.files[0];

  Papa.parse(file, {
    header: true,
    complete: function(results, file) {
      if (results) {
        data = results.data;
      }
    }
  })

  if (data) {
    console.log('p', data);
  }
}
bp123
  • 3,217
  • 8
  • 35
  • 74

1 Answers1

-1

You have used let to declare data, let usually have block scope, try using var:

var data;

Instead of:

let data;
Matheus Lacerda
  • 5,983
  • 11
  • 29
  • 45