Creating a very large multi-dimensional array

Discussion in 'JavaScript' started by bweb11, Feb 20, 2011.

  1. #1
    Could some one please tell me what's wrong with the below, i keep getting the error "Uncaught ReferenceError: array is not defined".

    
    var inflation=new array();
    
    inflation[1] = new Array();
    inflation[2] = new Array();
    inflation[3] = new Array();
    inflation[4] = new Array();
    inflation[5] = new Array();
    inflation[6] = new Array();
    inflation[7] = new Array();
    inflation[8] = new Array();
    inflation[9] = new Array();
    inflation[10] = new Array();
    inflation[11] = new Array();
    inflation[12] = new Array();
    inflation[13] = new Array();
    inflation[14] = new Array();
    inflation[15] = new Array();
    inflation[16] = new Array();
    inflation[17] = new Array();
    inflation[18] = new Array();
    inflation[19] = new Array();
    inflation[20] = new Array();
    inflation[21] = new Array();
    inflation[22] = new Array();
    inflation[23] = new Array();
    inflation[24] = new Array();
    inflation[25] = new Array();
    inflation[26] = new Array();
    inflation[27] = new Array();
    inflation[28] = new Array();
    inflation[29] = new Array();
    inflation[30] = new Array();
    inflation[31] = new Array();
    inflation[32] = new Array();
    inflation[33] = new Array();
    inflation[34] = new Array();
    inflation[35] = new Array();
    inflation[36] = new Array();
    inflation[37] = new Array();
    inflation[38] = new Array();
    inflation[39] = new Array();
    inflation[40] = new Array();
    inflation[41] = new Array();
    inflation[42] = new Array();
    inflation[43] = new Array();
    inflation[44] = new Array();
    inflation[45] = new Array();
    inflation[46] = new Array();
    inflation[47] = new Array();
    inflation[48] = new Array();
    inflation[49] = new Array();
    inflation[50] = new Array();
    inflation[51] = new Array();
    inflation[52] = new Array();
    inflation[53] = new Array();
    inflation[54] = new Array();
    inflation[55] = new Array();
    inflation[56] = new Array();
    inflation[57] = new Array();
    inflation[58] = new Array();
    inflation[59] = new Array();
    inflation[60] = new Array();
    inflation[61] = new Array();
    inflation[62] = new Array();
    inflation[63] = new Array();
    inflation[64] = new Array();
    inflation[65] = new Array();
    inflation[66] = new Array();
    inflation[67] = new Array();
    inflation[68] = new Array();
    inflation[69] = new Array();
    inflation[70] = new Array();
    inflation[71] = new Array();
    inflation[72] = new Array();
    inflation[73] = new Array();
    inflation[74] = new Array();
    inflation[75] = new Array();
    inflation[76] = new Array();
    inflation[77] = new Array();
    inflation[78] = new Array();
    inflation[79] = new Array();
    inflation[80] = new Array();
    inflation[81] = new Array();
    inflation[82] = new Array();
    inflation[83] = new Array();
    inflation[84] = new Array();
    inflation[85] = new Array();
    inflation[86] = new Array();
    inflation[87] = new Array();
    inflation[88] = new Array();
    inflation[89] = new Array();
    inflation[90] = new Array();
    inflation[91] = new Array();
    inflation[92] = new Array();
    inflation[93] = new Array();
    inflation[94] = new Array();
    inflation[95] = new Array();
    inflation[96] = new Array();
    inflation[97] = new Array();
    inflation[98] = new Array();
    inflation[99] = new Array();
    inflation[100] = new Array();
    inflation[101] = new Array();
    inflation[102] = new Array();
    inflation[103] = new Array();
    inflation[104] = new Array();
    inflation[105] = new Array();
    inflation[106] = new Array();
    inflation[107] = new Array();
    inflation[108] = new Array();
    inflation[109] = new Array();
    inflation[110] = new Array();
    inflation[111] = new Array();
    inflation[112] = new Array();
    inflation[113] = new Array();
    inflation[114] = new Array();
    inflation[115] = new Array();
    inflation[116] = new Array();
    inflation[117] = new Array();
    inflation[118] = new Array();
    inflation[119] = new Array();
    inflation[120] = new Array();
    inflation[121] = new Array();
    inflation[122] = new Array();
    inflation[123] = new Array();
    inflation[124] = new Array();
    inflation[125] = new Array();
    inflation[126] = new Array();
    inflation[127] = new Array();
    inflation[128] = new Array();
    inflation[129] = new Array();
    inflation[130] = new Array();
    inflation[131] = new Array();
    inflation[132] = new Array();
    inflation[133] = new Array();
    
    inflation[1][year] = 2000; 
    inflation[1][value] = 0.75;
    inflation[2][year] = 2000; 
    inflation[2][value] = 1.08;
    inflation[3][year] = 2000; 
    inflation[3][value] = 0.97;
    inflation[4][year] = 2000; 
    inflation[4][value] = 0.97;
    inflation[5][year] = 2000; 
    inflation[5][value] = 0.54;
    inflation[6][year] = 2000; 
    inflation[6][value] = 0.87;
    inflation[7][year] = 2000; 
    inflation[7][value] = 0.76;
    inflation[8][year] = 2000; 
    inflation[8][value] = 0.54;
    inflation[9][year] = 2000; 
    inflation[9][value] = 0.54;
    inflation[10][year] = 2000; 
    inflation[10][value] = 0.65;
    inflation[11][year] = 2000; 
    inflation[11][value] = 0.98;
    inflation[12][year] = 2000; 
    inflation[12][value] = 0.77;
    
    inflation[13][year] = 2001;
    inflation[13][value] = 1.07;
    inflation[14][year] = 2001;
    inflation[14][value] = 0.85;
    inflation[15][year] = 2001;
    inflation[15][value] = 1.28;
    inflation[16][year] = 2001;
    inflation[16][value] = 1.28;
    inflation[17][year] = 2001;
    inflation[17][value] = 1.83;
    inflation[18][year] = 2001;
    inflation[18][value] = 1.51;
    inflation[19][year] = 2001;
    inflation[19][value] = 1.71;
    inflation[20][year] = 2001;
    inflation[20][value] = 1.61;
    inflation[21][year] = 2001;
    inflation[21][value] = 1.18;
    inflation[22][year] = 2001;
    inflation[22][value] = 0.86;
    inflation[23][year] = 2001;
    inflation[23][value] = 0.76;
    inflation[24][year] = 2001;
    inflation[24][value] = 0.87;
    
    inflation[25][year] = 2002;
    inflation[25][value] = 1.69;
    inflation[26][year] = 2002;
    inflation[26][value] = 1.48;
    inflation[27][year] = 2002;
    inflation[27][value] = 1.27;
    inflation[28][year] = 2002;
    inflation[28][value] = 0.95;
    inflation[29][year] = 2002;
    inflation[29][value] = 1.06;
    inflation[30][year] = 2002;
    inflation[30][value] = 1.06;
    inflation[31][year] = 2002;
    inflation[31][value] = 0.63;
    inflation[32][year] = 2002;
    inflation[32][value] = 0.84;
    inflation[33][year] = 2002;
    inflation[33][value] = 1.38;
    inflation[34][year] = 2002;
    inflation[34][value] = 1.61;
    inflation[35][year] = 2002;
    inflation[35][value] = 1.50;
    inflation[36][year] = 2002;
    inflation[36][value] = 1.61;
    
    inflation[37][year] = 2003;
    inflation[37][value] = 1.25;
    inflation[38][year] = 2003;
    inflation[38][value] = 1.36;
    inflation[39][year] = 2003;
    inflation[39][value] = 1.36;
    inflation[40][year] = 2003;
    inflation[40][value] = 1.46;
    inflation[41][year] = 2003;
    inflation[41][value] = 1.36;
    inflation[42][year] = 2003;
    inflation[42][value] = 1.37;
    inflation[43][year] = 2003;
    inflation[43][value] = 1.05;
    inflation[44][year] = 2003;
    inflation[44][value] = 1.26;
    inflation[45][year] = 2003;
    inflation[45][value] = 1.47;
    inflation[46][year] = 2003;
    inflation[46][value] = 1.48;
    inflation[47][year] = 2003;
    inflation[47][value] = 1.59;
    inflation[48][year] = 2003;
    inflation[48][value] = 1.38;
    
    inflation[49][year] = 2004;
    inflation[49][value] = 1.64;
    inflation[50][year] = 2004;
    inflation[50][value] = 1.44;
    inflation[51][year] = 2004;
    inflation[51][value] = 1.23;
    inflation[52][year] = 2004;
    inflation[52][value] = 1.13;
    inflation[53][year] = 2004;
    inflation[53][value] = 1.34;
    inflation[54][year] = 2004;
    inflation[54][value] = 1.35;
    inflation[55][year] = 2004;
    inflation[55][value] = 1.66;
    inflation[56][year] = 2004;
    inflation[56][value] = 1.45;
    inflation[57][year] = 2004;
    inflation[57][value] = 1.14;
    inflation[58][year] = 2004;
    inflation[58][value] = 1.14;
    inflation[59][year] = 2004;
    inflation[59][value] = 1.25;
    inflation[60][year] = 2004;
    inflation[60][value] = 1.36;
    
    inflation[61][year] = 2005;
    inflation[61][value] = 1.92;
    inflation[62][year] = 2005;
    inflation[62][value] = 2.13;
    inflation[63][year] = 2005;
    inflation[63][value] = 2.34;
    inflation[64][year] = 2005;
    inflation[64][value] = 2.44;
    inflation[65][year] = 2005;
    inflation[65][value] = 2.34;
    inflation[66][year] = 2005;
    inflation[66][value] = 2.35;
    inflation[67][year] = 2005;
    inflation[67][value] = 1.94;
    inflation[68][year] = 2005;
    inflation[68][value] = 1.94;
    inflation[69][year] = 2005;
    inflation[69][value] = 1.94;
    inflation[70][year] = 2005;
    inflation[70][value] = 1.95;
    inflation[71][year] = 2005;
    inflation[71][value] = 1.65;
    inflation[72][year] = 2005;
    inflation[72][value] = 1.65;
    
    inflation[73][year] = 2006;
    inflation[73][value] = 2.97;
    inflation[74][year] = 2006;
    inflation[74][value] = 2.68;
    inflation[75][year] = 2006;
    inflation[75][value] = 2.48;
    inflation[76][year] = 2006;
    inflation[76][value] = 2.39;
    inflation[77][year] = 2006;
    inflation[77][value] = 2.49;
    inflation[78][year] = 2006;
    inflation[78][value] = 2.40;
    inflation[79][year] = 2006;
    inflation[79][value] = 2.50;
    inflation[80][year] = 2006;
    inflation[80][value] = 2.20;
    inflation[81][year] = 2006;
    inflation[81][value] = 2.01;
    inflation[82][year] = 2006;
    inflation[82][value] = 1.81;
    inflation[83][year] = 2006;
    inflation[83][value] = 2.13;
    inflation[84][year] = 2006;
    inflation[84][value] = 1.93;
    
    inflation[85][year] = 2007;
    inflation[85][value] = 2.12;
    inflation[86][year] = 2007;
    inflation[86][value] = 2.13;
    inflation[87][year] = 2007;
    inflation[87][value] = 2.03;
    inflation[88][year] = 2007;
    inflation[88][value] = 1.75;
    inflation[89][year] = 2007;
    inflation[89][value] = 1.75;
    inflation[90][year] = 2007;
    inflation[90][value] = 1.85;
    inflation[91][year] = 2007;
    inflation[91][value] = 2.44;
    inflation[92][year] = 2007;
    inflation[92][value] = 2.54;
    inflation[93][year] = 2007;
    inflation[93][value] = 2.75;
    inflation[94][year] = 2007;
    inflation[94][value] = 3.07;
    inflation[95][year] = 2007;
    inflation[95][value] = 2.78;
    inflation[96][year] = 2007;
    inflation[96][value] = 2.69;
    
    inflation[97][year] = 2008;
    inflation[97][value] = 3.11;
    inflation[98][year] = 2008;
    inflation[98][value] = 4.07;
    inflation[99][year] = 2008;
    inflation[99][value] = 4.46;
    inflation[100][year] = 2008;
    inflation[100][value] = 5.25;
    inflation[101][year] = 2008;
    inflation[101][value] = 4.78;
    inflation[102][year] = 2008;
    inflation[102][value] = 4.41;
    inflation[103][year] = 2008;
    inflation[103][value] = 3.81;
    inflation[104][year] = 2008;
    inflation[104][value] = 3.34;
    inflation[105][year] = 2008;
    inflation[105][value] = 2.97;
    inflation[106][year] = 2008;
    inflation[106][value] = 2.40;
    inflation[107][year] = 2008;
    inflation[107][value] = 2.51;
    inflation[108][year] = 2008;
    inflation[108][value] = 2.23;
    
    inflation[109][year] = 2009;
    inflation[109][value] = 2.83;
    inflation[110][year] = 2009;
    inflation[110][value] = 1.91;
    inflation[111][year] = 2009;
    inflation[111][value] = 1.55;
    inflation[112][year] = 2009;
    inflation[112][value] = 1.09;
    inflation[113][year] = 2009;
    inflation[113][value] = 1.55;
    inflation[114][year] = 2009;
    inflation[114][value] = 1.74;
    inflation[115][year] = 2009;
    inflation[115][value] = 1.83;
    inflation[116][year] = 2009;
    inflation[116][value] = 2.22;
    inflation[117][year] = 2009;
    inflation[117][value] = 2.32;
    inflation[118][year] = 2009;
    inflation[118][value] = 2.91;
    inflation[119][year] = 2009;
    inflation[119][value] = 3.10;
    inflation[120][year] = 2009;
    inflation[120][value] = 3.03;
    
    inflation[121][year] = 2010;
    inflation[121][value] = 3.73;
    inflation[122][year] = 2010;
    inflation[122][value] = 3.21;
    inflation[123][year] = 2010;
    inflation[123][value] = 3.13;
    inflation[124][year] = 2010;
    inflation[124][value] = 3.05;
    inflation[125][year] = 2010;
    inflation[125][value] = 3.14;
    inflation[126][year] = 2010;
    inflation[126][value] = 3.07;
    inflation[127][year] = 2010;
    inflation[127][value] = 3.24;
    inflation[128][year] = 2010;
    inflation[128][value] = 3.34;
    inflation[129][year] = 2010;
    inflation[129][value] = 3.72;
    inflation[130][year] = 2010;
    inflation[130][value] = 3.37;
    inflation[131][year] = 2010;
    inflation[131][value] = 3.01;
    inflation[132][year] = 2010;
    inflation[132][value] = 3.40;
    
    inflation[133][year] = 2011;
    inflation[133][value] = 4.00;
    
    Code (markup):
    Also, the function i normally use to display contents of an array is:

    
    function showme()
    {
    for(var i=0;i<arr.length;i++){
    document.write("<b>arr["+i+"] is </b>=>"+arr[i]+"<br>");
    }
    }
    
    Code (markup):
    could someone please tell me how i would go about modifiying this for the array above.
     
    bweb11, Feb 20, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This works
    
    <html>
    <head>
    <script type='text/javascript'>
    var inflation = new Array();
    inflation[1] = new Array('year','value');
    inflation[1]['year'] = 2000; 
    inflation[1]['value'] = 0.75;
    inflation[2] = new Array('year','value');
    inflation[2]['year'] = 2000;
    inflation[2]['value'] = 1.08;
    
    function showme() {
    	for(var i=1;i<inflation.length;i++) {
    	document.write("<b>inflation["+i+"] year is </b>=>"+inflation[i].year+"<br>");
    	document.write("<b>inflation["+i+"] value is </b>=>"+inflation[i].value+"<br>");
    	}
    }
    </script>
    </head>
    <body onload="showme()">
    </body>
    </html>
    
    Code (markup):
    But you can also make a multi-dimensional associative array like this:
    
    <html>
    <head>
    <script  type='text/javascript'>
    var inflation = new Array();
    inflation[0] = { 'year':2000, 'value':0.75 };
    inflation[1] = { 'year':2000, 'value':1.08 };
    
    function showme() {
    	for(var i=0;i<inflation.length;i++) {
    	document.write("<b>inflation["+i+"] year is </b>=>"+inflation[i].year+"<br>");
    	document.write("<b>inflation["+i+"] value is </b>=>"+inflation[i].value+"<br>");
    	}
    }
    </script>
    </head>
    <body onload="showme()">
    </body>
    </html>
    
    Code (markup):
     
    Last edited: Feb 20, 2011
    Cash Nebula, Feb 20, 2011 IP
  3. bweb11

    bweb11 Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That's wonderful thank you.
    At the start is used:
    
    var inflation = [];
    
    Code (markup):
     
    bweb11, Feb 21, 2011 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    You may be better off doing this server-side with a database of the values..
     
    camjohnson95, Feb 21, 2011 IP