Currently experiencing a similar issue with Papaparse, which may be attributed to my level of familiarity with the library and its callbacks. However, I can provide some guidance on where you might find a solution.
The reason why your display_links
is returning an empty array is due to the asynchronous nature of the complete
callback function in Papaparse. The assignment of display_links
occurs after the file has been completely processed, making it unavailable for logging at that point. In essence, this approach will not yield the desired result.
To resolve this problem, I suggest encapsulating your intended actions for display_links
within a separate function. Then, from within the complete
callback, call this function with display_links
as an argument. This way, your function will execute with the parsed results.
If this solution does not meet your needs, I recommend further exploration into Asynchronous JavaScript and how callbacks operate to discover a more suitable approach for your situation.
A personal challenge I encountered was attempting to abstract the parsing process within a function and have it return the final result once the file had been read/parsed. Unfortunately, calling another function from the complete
callback seemed to be the only viable option, as direct return statements did not work as expected.
References:
- Papaparse Docs - Look for information on
complete
.
- Asynchronous JavaScript - Mozilla Link