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

  • Home
  • SEARCH
  • 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
  • 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-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 a flat-file schema that has a header and detail records. It looks
I have a series of ASCII flat files coming in from a mainframe to
Essentially, I have to get a flat file into a database. The flat files
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a windows mobile 5.0 application (smartphone) that contains a flat data file
We have written a number of SSIS packages that import data from CSV files
I've created a flat file schema in Visual Studio from an instance of a
I have a fixed-width flat file. To make matters worse, each line can either
My goal is to have a CMS that is totally self-contained like a flat-file
i have a input tag which is non editable, but some times i need

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.