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 6569993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:42:02+00:00 2026-05-25T14:42:02+00:00

I have a simple CSV (imported using JQuery’s $.ajax from the /data/league.csv on the

  • 0

I have a simple CSV (imported using JQuery’s $.ajax from the /data/league.csv on the same site) with three lines in this exact format:

"Kimberlin Library","Queen's Building","Innovation Centre","etc etc"
8,2,0,-2
1,0,-1,0

which I’d like to get into this format (to use building and percent as data for the x-y axes in Highcharts, and also to populate a list with all three):

var leaguetable = {
    building: ["Kimberlin Library","Queen's Building","Innovation Centre","etc etc"],
    percent: [8,2,0,-2],
    change: [1,0,-1,0]
};

embarrassingly trivial, but I keep drawing a blank, despite trying other people’s methods (including split(/\r\n|\n|r/), searching for /^(.*)$/m), and this question), so prepared to start from scratch. I need something as simple as possible, either JQuery or pure Javascript. For a similar problem I ended up converting the file to JSON, but I’d like to avoid that if possible.

  • 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-25T14:42:03+00:00Added an answer on May 25, 2026 at 2:42 pm

    Try this. It will handle simple CSV, and single- or double-quoted CSV, all via the regex pattern in the code below. You’ll have to adjust the end of processCSV() to do what you want, since I’m just returning the object into thin air.

    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "my_csv.txt",
            dataType: "text",
            success: function(data) {processCSV(data);}
         });
     });
    
    function processCSV(allLines) {
        var allLinesArray = allLines.split(/\r\n|\n/);
        var leaguetable = { 'building': [], 'percent': [], 'change': [] };
        var pattern = /([^,'"]*"[^"]*"[^,'"]*)|([^,'"]*'[^']*'[^,'"]*)|([^,"']*)/ig;
        var fieldValues;
    
        for (var i=0; i<allLinesArray.length; i++) {
            fieldValues = allLinesArray[i].match(pattern);
            if (fieldValues) {
                for (var j=0; j<fieldValues.length; j++) {
                    // if begins with single- or double-quote, strip specified quotes
                    if (fieldValues[j].charAt(0) === '"' || fieldValues[j].charAt(0) === "'") {
                        fieldValues[j] = fieldValues[j].replace(fieldValues[j].substr(0,1), "");
                    }
                }
                // I'll trust your CSV to have the right number of fields, but...
                // you may want to build some validation in before doing the next 3 lines
                leaguetable.building.push(fieldValues[1]);
                leaguetable.percent.push(fieldValues[2]);
                leaguetable.change.push(fieldValues[3]);
            }
        }
        return leaguetable;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple jQuery: $.get('Data.csv', function(data) { alert(data); }); Data.csv is stored
I have simple SSIS package which reads data from flat file and insert into
I have a simple .csv file that has that I want to extract data
I have a simple rake task importing records from a CSV file and saving
I have a simple Android App using simple js, jquery mobile and phonegap that
I have written a simple perl script to read a line from a .csv
I have a simple report that I want to export to a CSV file.
I have another csv file where I am trying to do a simple word
I have a simple Ruby script that looks like this require 'csv' while line
I am trying to read a very simple but somehow large(800Mb) csv file using

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.