Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7573449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:11:08+00:00 2026-05-30T16:11:08+00:00

I am using this to parse a csv file and create an array data

  • 0

I am using this to parse a csv file and create an array data as specified in d3 docs:

d3.csv("afile.csv", function(data) {
    data.forEach(function(d) {
    d.date = formatDate.parse(d.date);
    d.price = +d.price;
});

However, if after this method I try to call data[0] it says it is undefined. Is this because data is a reference and once d3.csv() is out of scope is destroyed? If this is the case how can I overcome this. I need to reference data out of d3.csv()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:11:09+00:00Added an answer on May 30, 2026 at 4:11 pm

    d3.csv is an asynchronous method. This means that code inside the callback function is run when the data is loaded, but code after and outside the callback function will be run immediately after the request is made, when the data is not yet available. In other words:

    first();
    d3.csv("path/to/file.csv", function(rows) {
      third();
    });
    second();
    

    If you want to use the data that is loaded by d3.csv, you either need to put that code inside the callback function (where third is, above):

    d3.csv("path/to/file.csv", function(rows) {
      doSomethingWithRows(rows);
    });
    
    function doSomethingWithRows(rows) {
      // do something with rows
    }
    

    Or, you might save it as a global variable on the window that you can then refer to later:

    var rows;
    
    d3.csv("path/to/file.csv", function(loadedRows) {
      rows = loadedRows;
      doSomethingWithRows();
    });
    
    function doSomethingWithRows() {
      // do something with rows
    }
    

    If you want, you can also assign the loaded data explicitly to the window object, rather than declaring a variable and then managing two different names:

    d3.csv("path/to/file.csv", function(rows) {
      window.rows = rows;
      doSomethingWithRows();
    });
    
    function doSomethingWithRows() {
      // do something with rows
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the code from this tutorial to parse a CSV file and
I'm using chcsvparser to parse data from a csv file on my apps launch.
I'm trying to parse an xml file with PHP. I'm using this code and
I parse data using JSON in javascript, I find this is very convenient. But
Currently I am using MySQLi to parse a CSV file into a Database, that
for my application i have to parse CSV file using Erlang.following is the code
I need to parse an CSV file using AWK. A line in the CSV
We're using OpenCSV to parse a CSV file and bind its values directly to
I have CSV data loaded into a multidimensional array. In this way each row
I'm trying to parse a CSV file using Python's csv module (specifically, the DictReader

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.