-1

What is the best way to create and populate a three dimensional array by inserting a two dimensional array?

Say I have an array

    var arrState = {
        ME: ['Maine','1,328,361'],
            etc
    };

And I want to store the current values in that array each time a function is ran. Would something like this work?

var arrStateHistory;
var i = 0;

function start(){
i++;
arrHistory[i] = arrState;

}
1
  • What happens when you run it? Commented May 12, 2012 at 1:23

1 Answer 1

0

arrState is an object, so you'd have to iterate with for...in. Why not use objects for everything?

var States = {
  ME: {
    name: 'Maine',
    population: 1328361
  },
  FL: {
    name: 'Florida'
    ...
  }
  ...
}

Then you can add a new state or modify one like this:

States.WA = {
  name: 'Washington',
  population: 1000000
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.