 <p>You need to <em>return</em> the month value. You also need to write the function properly:</p> <pre><code>function getMonthName(n) { var months = ["Jan", "Feb", ... ]; // omitted for brevity return months[n - 1]; } </code></pre> <p>with usage:</p> <pre><code>for (var i=0; i &lt; arrayLength; i++) { var month = data[1]; var name = getMonthName(month); alert(name); } </code></pre> <p>NB: the result will be <code>undefined</code> if the supplied month is out of range.</p>