How to pass an array through Javascript Function Arguments
<p>I have found a couple other similar threads on stackoverflow (<a href="https://stackoverflow.com/questions/2856059/passing-an-array-as-a-function-parameter-in-javascript%22Passing%20an%20array%20as%20a%20function%20parameter%20in%20Javascript%22">Pass Array Thread 2)</a> and (<a href="https://stackoverflow.com/questions/13096352/javascript-pass-an-array-to-a-function">Pass Array Thread 1</a>) as well as from a few other sites but I either did not understand them, they did not fully answer my question, or I did not know how to implement it into my code. </p>

<p>I have the following code which should create a map for a game based on some arrays: </p>

<pre><code>function createMap(level) {
   var map = document.getElementById('map');
   mapWidth = parseInt(level[0]);
   mapHeight = parseInt(level[1]);
   map.innerHTML = '';
   rowNumber = 1;
   tileID = 1;
   var consoleHelp = level[7];
   console.log(k+' and value is '+consoleHelp);
   k = 1;
for (k = 1; k &lt;= mapHeight; k++) { // repeat below loop until specified height is reached
 for (k = 1; k &lt;= mapWidth; k++) { // create a row of tiles based on the specified width of the array
    console.log('Row '+k+' created')
    if (rowNumber == 1) {
        k++;
    }
    else {
        k--;
    }
    if (level[k] == 'w') {
        map.innerHTML += '&lt;span id="'+rowNumber+'-'+tileID+'"&gt;desert&lt;image class="tiles" src="desert.png"&gt;&lt;/span&gt;';
    }
    else if (level[k] == 'g') {
        map.innerHTML += '&lt;span id="'+rowNumber+'-'+tileID+'"&gt;&lt;image class="tiles" src="grass.png"&gt;&lt;/span&gt;';
    }
    else {
        console.log('crap dis did not work');
        var consoleHelp = level[k];
        console.log(k+' and value is '+consoleHelp);
    }
    if (rowNumber == 1) {
        k--;
    }
    else {
    k++;
    }
    tileID++
  }
  rowNumber++
  level = level + '_1';
  map.innerHTML = "&lt;br&gt;";
}
spawnTile();
}
</code></pre>

<p>and the variable arrays (incomplete but you get the idea): </p>

<pre><code>var map_beginning_1 =         ['20','10','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w'];
var map_beginning_1_1 =                 ['w','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','w'];
</code></pre>

<p>My problem is that I call in</p>

<pre><code>createMap('map_beginning_1')
</code></pre>

<p>and nothing happens. There's no errors but nothing else happens. I did a test to see what it was getting and the value of "level[7]" is "i" and "level<a href="https://stackoverflow.com/questions/2856059/passing-an-array-as-a-function-parameter-in-javascript%22Passing%20an%20array%20as%20a%20function%20parameter%20in%20Javascript%22">1</a>" is "a", which is the location of the characters in "map_beginning_1". Can someone please explain to me how to or if it's even possible to variably pass an array through a Javascript function argument and how to do it? And if it isn't possible, can you suggest any alternatives for what I'm trying to do? Javascript is preferable but I can use Jquery if I must.</p>