Move results of papaparse into array Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?How to move an element into another element?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?Detecting a mobile browser
Is CEO the "profession" with the most psychopaths?
Can an alien society believe that their star system is the universe?
Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?
Is a ledger board required if the side of my house is wood?
Project Euler #1 in C++
How would a mousetrap for use in space work?
Question about debouncing - delay of state change
Does the Weapon Master feat grant you a fighting style?
Selecting user stories during sprint planning
Performance gap between vector<bool> and array
How to write the following sign?
How to react to hostile behavior from a senior developer?
How do living politicians protect their readily obtainable signatures from misuse?
How often does castling occur in grandmaster games?
Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?
Why is Nikon 1.4g better when Nikon 1.8g is sharper?
What does it mean that physics no longer uses mechanical models to describe phenomena?
Is it fair for a professor to grade us on the possession of past papers?
A term for a woman complaining about things/begging in a cute/childish way
Should I follow up with an employee I believe overracted to a mistake I made?
Disembodied hand growing fangs
Did Krishna say in Bhagavad Gita "I am in every living being"
Chinese Seal on silk painting - what does it mean?
Is it possible for SQL statements to execute concurrently within a single session in SQL Server?
Move results of papaparse into array
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?How to move an element into another element?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?Detecting a mobile browser
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm using papaparse to parse a local csv file using the following:
var display_links = [];
Papa.parse(file_links,
header: true,
download: true,
dynamicTyping: true,
complete: function (results)
results.data.push(display_links)
);
console.log(display_links)
How do I push the results of the parse into a local array so I can use it in other functions/processes?
console.log(display_links)
Returns an empty array.
javascript papaparse
add a comment |
I'm using papaparse to parse a local csv file using the following:
var display_links = [];
Papa.parse(file_links,
header: true,
download: true,
dynamicTyping: true,
complete: function (results)
results.data.push(display_links)
);
console.log(display_links)
How do I push the results of the parse into a local array so I can use it in other functions/processes?
console.log(display_links)
Returns an empty array.
javascript papaparse
lol it's actually called papaparse? thought it was a typo
– kkarakk
Mar 9 at 6:08
add a comment |
I'm using papaparse to parse a local csv file using the following:
var display_links = [];
Papa.parse(file_links,
header: true,
download: true,
dynamicTyping: true,
complete: function (results)
results.data.push(display_links)
);
console.log(display_links)
How do I push the results of the parse into a local array so I can use it in other functions/processes?
console.log(display_links)
Returns an empty array.
javascript papaparse
I'm using papaparse to parse a local csv file using the following:
var display_links = [];
Papa.parse(file_links,
header: true,
download: true,
dynamicTyping: true,
complete: function (results)
results.data.push(display_links)
);
console.log(display_links)
How do I push the results of the parse into a local array so I can use it in other functions/processes?
console.log(display_links)
Returns an empty array.
javascript papaparse
javascript papaparse
asked Mar 8 at 20:20
stephen.webbstephen.webb
315
315
lol it's actually called papaparse? thought it was a typo
– kkarakk
Mar 9 at 6:08
add a comment |
lol it's actually called papaparse? thought it was a typo
– kkarakk
Mar 9 at 6:08
lol it's actually called papaparse? thought it was a typo
– kkarakk
Mar 9 at 6:08
lol it's actually called papaparse? thought it was a typo
– kkarakk
Mar 9 at 6:08
add a comment |
2 Answers
2
active
oldest
votes
In your complete function you can replace results.data.push(display_links) with a reassignment: display_links = results.data;. It seems you have it backwards.
If you have declared display_links outside that function scope you should have access to the results later on. So the easy solution is to just pull it out of the local scope.
If that's not feasible, please provide a more complete example.
let display_links = [];
function doSomethingWithDisplayLinks(results)
display_links = results;
console.log('display_links before:', display_links);
doSomethingWithDisplayLinks(['http://www.google.com']);
console.log('display_links after:', display_links);
Ah, I had assigned it back to front. Thank you.
– stephen.webb
Mar 11 at 13:27
add a comment |
Facing a similar issue with Papaparse or it is my current knowledge with the library and callbacks. Though I can point you in the direction where you might be able to find an answer for yourself.
First thing, your display_links comes up an empty array because when parsing file via Papaparse, the complete is an asynchronous callback function which means your assignment of display_links inside the callback happens asynchronously after the file that you selected is completly processed. So when you log your variable, it is not yet assigned the result. In short this would not work.
Now to solve your problem, the only answer that I have found is that whatever plans you have for display_links, you can put them in a function and from inside complete, call that function with display_links as argument. That way, your function would be executed with the results of the parse.
Look up into Asynchronous JS and how callback works to find a more optimal solution for yourself if this does not work for you.
Side note - My issue is, I wanted to abstract the parsing and other related actions inside a function and once the file would have been read / parsed, that function would return the end result back. This last part of retunring the end result, is something I am not able to accomplish as I think you can only move forward and call another function from the complete callback and returning does not work :/
Ref -
Papaparse Docs -> Search forcomplete.- Asynchronous JS - Mozilla Link
Found a way to make this work for me. The way I did it was, I passed in a callback to the first function uses Papaparse to parse and then upon completion, just called that from thecomplete. Not sure if it is the best but that worked for me, sorta :P
– Tannu
Mar 11 at 10:06
Thank you - I hadn't appreciated the asynchronous angle. Now when I push results.data into the display_links array and then call a console.log from a secondary function, it logs the array properly.
– stephen.webb
Mar 11 at 13:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070466%2fmove-results-of-papaparse-into-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your complete function you can replace results.data.push(display_links) with a reassignment: display_links = results.data;. It seems you have it backwards.
If you have declared display_links outside that function scope you should have access to the results later on. So the easy solution is to just pull it out of the local scope.
If that's not feasible, please provide a more complete example.
let display_links = [];
function doSomethingWithDisplayLinks(results)
display_links = results;
console.log('display_links before:', display_links);
doSomethingWithDisplayLinks(['http://www.google.com']);
console.log('display_links after:', display_links);
Ah, I had assigned it back to front. Thank you.
– stephen.webb
Mar 11 at 13:27
add a comment |
In your complete function you can replace results.data.push(display_links) with a reassignment: display_links = results.data;. It seems you have it backwards.
If you have declared display_links outside that function scope you should have access to the results later on. So the easy solution is to just pull it out of the local scope.
If that's not feasible, please provide a more complete example.
let display_links = [];
function doSomethingWithDisplayLinks(results)
display_links = results;
console.log('display_links before:', display_links);
doSomethingWithDisplayLinks(['http://www.google.com']);
console.log('display_links after:', display_links);
Ah, I had assigned it back to front. Thank you.
– stephen.webb
Mar 11 at 13:27
add a comment |
In your complete function you can replace results.data.push(display_links) with a reassignment: display_links = results.data;. It seems you have it backwards.
If you have declared display_links outside that function scope you should have access to the results later on. So the easy solution is to just pull it out of the local scope.
If that's not feasible, please provide a more complete example.
let display_links = [];
function doSomethingWithDisplayLinks(results)
display_links = results;
console.log('display_links before:', display_links);
doSomethingWithDisplayLinks(['http://www.google.com']);
console.log('display_links after:', display_links);In your complete function you can replace results.data.push(display_links) with a reassignment: display_links = results.data;. It seems you have it backwards.
If you have declared display_links outside that function scope you should have access to the results later on. So the easy solution is to just pull it out of the local scope.
If that's not feasible, please provide a more complete example.
let display_links = [];
function doSomethingWithDisplayLinks(results)
display_links = results;
console.log('display_links before:', display_links);
doSomethingWithDisplayLinks(['http://www.google.com']);
console.log('display_links after:', display_links);let display_links = [];
function doSomethingWithDisplayLinks(results)
display_links = results;
console.log('display_links before:', display_links);
doSomethingWithDisplayLinks(['http://www.google.com']);
console.log('display_links after:', display_links);let display_links = [];
function doSomethingWithDisplayLinks(results)
display_links = results;
console.log('display_links before:', display_links);
doSomethingWithDisplayLinks(['http://www.google.com']);
console.log('display_links after:', display_links);edited Mar 8 at 20:30
answered Mar 8 at 20:25
manonthematmanonthemat
3,180931
3,180931
Ah, I had assigned it back to front. Thank you.
– stephen.webb
Mar 11 at 13:27
add a comment |
Ah, I had assigned it back to front. Thank you.
– stephen.webb
Mar 11 at 13:27
Ah, I had assigned it back to front. Thank you.
– stephen.webb
Mar 11 at 13:27
Ah, I had assigned it back to front. Thank you.
– stephen.webb
Mar 11 at 13:27
add a comment |
Facing a similar issue with Papaparse or it is my current knowledge with the library and callbacks. Though I can point you in the direction where you might be able to find an answer for yourself.
First thing, your display_links comes up an empty array because when parsing file via Papaparse, the complete is an asynchronous callback function which means your assignment of display_links inside the callback happens asynchronously after the file that you selected is completly processed. So when you log your variable, it is not yet assigned the result. In short this would not work.
Now to solve your problem, the only answer that I have found is that whatever plans you have for display_links, you can put them in a function and from inside complete, call that function with display_links as argument. That way, your function would be executed with the results of the parse.
Look up into Asynchronous JS and how callback works to find a more optimal solution for yourself if this does not work for you.
Side note - My issue is, I wanted to abstract the parsing and other related actions inside a function and once the file would have been read / parsed, that function would return the end result back. This last part of retunring the end result, is something I am not able to accomplish as I think you can only move forward and call another function from the complete callback and returning does not work :/
Ref -
Papaparse Docs -> Search forcomplete.- Asynchronous JS - Mozilla Link
Found a way to make this work for me. The way I did it was, I passed in a callback to the first function uses Papaparse to parse and then upon completion, just called that from thecomplete. Not sure if it is the best but that worked for me, sorta :P
– Tannu
Mar 11 at 10:06
Thank you - I hadn't appreciated the asynchronous angle. Now when I push results.data into the display_links array and then call a console.log from a secondary function, it logs the array properly.
– stephen.webb
Mar 11 at 13:29
add a comment |
Facing a similar issue with Papaparse or it is my current knowledge with the library and callbacks. Though I can point you in the direction where you might be able to find an answer for yourself.
First thing, your display_links comes up an empty array because when parsing file via Papaparse, the complete is an asynchronous callback function which means your assignment of display_links inside the callback happens asynchronously after the file that you selected is completly processed. So when you log your variable, it is not yet assigned the result. In short this would not work.
Now to solve your problem, the only answer that I have found is that whatever plans you have for display_links, you can put them in a function and from inside complete, call that function with display_links as argument. That way, your function would be executed with the results of the parse.
Look up into Asynchronous JS and how callback works to find a more optimal solution for yourself if this does not work for you.
Side note - My issue is, I wanted to abstract the parsing and other related actions inside a function and once the file would have been read / parsed, that function would return the end result back. This last part of retunring the end result, is something I am not able to accomplish as I think you can only move forward and call another function from the complete callback and returning does not work :/
Ref -
Papaparse Docs -> Search forcomplete.- Asynchronous JS - Mozilla Link
Found a way to make this work for me. The way I did it was, I passed in a callback to the first function uses Papaparse to parse and then upon completion, just called that from thecomplete. Not sure if it is the best but that worked for me, sorta :P
– Tannu
Mar 11 at 10:06
Thank you - I hadn't appreciated the asynchronous angle. Now when I push results.data into the display_links array and then call a console.log from a secondary function, it logs the array properly.
– stephen.webb
Mar 11 at 13:29
add a comment |
Facing a similar issue with Papaparse or it is my current knowledge with the library and callbacks. Though I can point you in the direction where you might be able to find an answer for yourself.
First thing, your display_links comes up an empty array because when parsing file via Papaparse, the complete is an asynchronous callback function which means your assignment of display_links inside the callback happens asynchronously after the file that you selected is completly processed. So when you log your variable, it is not yet assigned the result. In short this would not work.
Now to solve your problem, the only answer that I have found is that whatever plans you have for display_links, you can put them in a function and from inside complete, call that function with display_links as argument. That way, your function would be executed with the results of the parse.
Look up into Asynchronous JS and how callback works to find a more optimal solution for yourself if this does not work for you.
Side note - My issue is, I wanted to abstract the parsing and other related actions inside a function and once the file would have been read / parsed, that function would return the end result back. This last part of retunring the end result, is something I am not able to accomplish as I think you can only move forward and call another function from the complete callback and returning does not work :/
Ref -
Papaparse Docs -> Search forcomplete.- Asynchronous JS - Mozilla Link
Facing a similar issue with Papaparse or it is my current knowledge with the library and callbacks. Though I can point you in the direction where you might be able to find an answer for yourself.
First thing, your display_links comes up an empty array because when parsing file via Papaparse, the complete is an asynchronous callback function which means your assignment of display_links inside the callback happens asynchronously after the file that you selected is completly processed. So when you log your variable, it is not yet assigned the result. In short this would not work.
Now to solve your problem, the only answer that I have found is that whatever plans you have for display_links, you can put them in a function and from inside complete, call that function with display_links as argument. That way, your function would be executed with the results of the parse.
Look up into Asynchronous JS and how callback works to find a more optimal solution for yourself if this does not work for you.
Side note - My issue is, I wanted to abstract the parsing and other related actions inside a function and once the file would have been read / parsed, that function would return the end result back. This last part of retunring the end result, is something I am not able to accomplish as I think you can only move forward and call another function from the complete callback and returning does not work :/
Ref -
Papaparse Docs -> Search forcomplete.- Asynchronous JS - Mozilla Link
answered Mar 9 at 6:00
TannuTannu
4010
4010
Found a way to make this work for me. The way I did it was, I passed in a callback to the first function uses Papaparse to parse and then upon completion, just called that from thecomplete. Not sure if it is the best but that worked for me, sorta :P
– Tannu
Mar 11 at 10:06
Thank you - I hadn't appreciated the asynchronous angle. Now when I push results.data into the display_links array and then call a console.log from a secondary function, it logs the array properly.
– stephen.webb
Mar 11 at 13:29
add a comment |
Found a way to make this work for me. The way I did it was, I passed in a callback to the first function uses Papaparse to parse and then upon completion, just called that from thecomplete. Not sure if it is the best but that worked for me, sorta :P
– Tannu
Mar 11 at 10:06
Thank you - I hadn't appreciated the asynchronous angle. Now when I push results.data into the display_links array and then call a console.log from a secondary function, it logs the array properly.
– stephen.webb
Mar 11 at 13:29
Found a way to make this work for me. The way I did it was, I passed in a callback to the first function uses Papaparse to parse and then upon completion, just called that from the
complete. Not sure if it is the best but that worked for me, sorta :P– Tannu
Mar 11 at 10:06
Found a way to make this work for me. The way I did it was, I passed in a callback to the first function uses Papaparse to parse and then upon completion, just called that from the
complete. Not sure if it is the best but that worked for me, sorta :P– Tannu
Mar 11 at 10:06
Thank you - I hadn't appreciated the asynchronous angle. Now when I push results.data into the display_links array and then call a console.log from a secondary function, it logs the array properly.
– stephen.webb
Mar 11 at 13:29
Thank you - I hadn't appreciated the asynchronous angle. Now when I push results.data into the display_links array and then call a console.log from a secondary function, it logs the array properly.
– stephen.webb
Mar 11 at 13:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070466%2fmove-results-of-papaparse-into-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
lol it's actually called papaparse? thought it was a typo
– kkarakk
Mar 9 at 6:08