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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:22:22+00:00 2026-05-22T12:22:22+00:00

I have a flat CSV file which I need read from to end up

  • 0

I have a flat CSV file which I need read from to end up with 3 select boxes for region, country, city.

I’m using jQuery to load the csv file, and jQuery Csv plugin to return the csv file as an array.

I have looped through the array and built an array of the countries, but am now struggling to add the cities to the array. What structure would be best? Ideally I just want to loop over the csv once, and end up with one nested array, which has regions, then countries ten cities.

Is this a case for an associative array?

Thanks for any help.

Ian.

  • 1 1 Answer
  • 1 View
  • 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-22T12:22:23+00:00Added an answer on May 22, 2026 at 12:22 pm

    Yes, associative arrays are fine for that, something like this:

    var data = [
        ['europe', 'belgium', 'brussels'],
        ['europe', 'france', 'paris'],
        ['europe', 'france', 'lyon'],
        ['americas', 'usa', 'washington'],
        ['americas', 'usa', 'new-york'],
        ['americas', 'chile', 'santiago']
    ];
    
    var tree = {},
        l = data.length,
        region, country;
    while(l--){
        region = data[l][0];
        country = data[l][1];
        tree[region] = tree[region] || {};
        tree[region][country] = tree[region][country] || [];
        tree[region][country].push( data[l][2] );
    }
    console.log(tree);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package where I import data from flat file into SQL
I have a flat data file that I need to import into my SQL
I have a Flat File Source that reads data from a file with two
SSIS 2005 I have a flat file connection which is the result of a
I have flat file. I am loading data from flat file to source table
I have a flat file source from Excel that has a structure like this:
Lets say, I have a flat text file in a server. I need to
I have a flat file of records, each 33 lines long. I need to
I have a flat-file schema that has a header and detail records. It looks

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.