First of all, i would like to start out with an introduction. I am Thoughtx3, i came here not too long ago, hoping to learn more Java + Java Script. I then realized, i just like Maplestory, and wish to learn how to code with Maplestory-based Java + java script. I have learned quite a bit, thanks to some of the people i have met, plus tutorials within here and ********(Sorry if i am advertising, or anything.).
Now, let's start out with a explanation of an array. An array is a way to shorten selections, in my own words. Example, you currently have 56 selections, you could merely shorten it to 1 selection. Arrays are quite simple to create. Now, you know var is needed for almost any array/variable. Unless, the variable is global, and var is not required. Example of an array, and no "var":
PHP Code:

array = ["", "..."];

function
start() {
var
array2 = "Hello.\r\n"; // Is not a global variable.



Now, that you know when to use var in a npc, or not, let's get started on when to use []; or new Array();
PHP Code:

var array = new Array("Hi", "Hi.");



the new Array(); part is only used for single dimension arrays. This can be used for both single dimensional, or multi-dimensional.
PHP Code:

var array = [[4030002, 4030003], [4030004, 4030005]]; // Depending if it is a global variable. Multi-dimensional.



Now, you know how to make an array with all those examples. Now let's get started how to display/use an array. This is how you can display single dimensional arrays(Bunch of codes):
PHP Code:

#L" + i + "#" + array[i] + "#l\r\n // How you display it, but you first need this:
for (var i = 0;i < array.length; i++) // The infamous For Loop.



To give an answer to the array, for the selections, you can use:
[selection]
Example:
PHP Code:

cm.gainItem(array[selection], 1);



That is all my knowledge on arrays, i will be adding on, correcting my mistakes, so on so forth.

Credits:
Syre - Helped me with a question.
ThoughtxD(Me.)

Here is an example of a NPC(Please note, that this is just a NPC with random ids.):
PHP Code:

items = [4030002, 1072007, 1072006];

function
start() {
var
text = "Hello. Choose one(Requires 1 meso.):\r\n";
for (var
i = 0;i < items.length; i++)
text += "#L" + i + "##i" + items[i] + "##l\r\n\r\n";
cm.sendSimple(text);
}

function
action(mode, type, selection) {
if (
mode == 0) {
if (
cm.getPlayer().getMesos() >= 1) {
cm.gainItem(items[selection], 1);
cm.getPlayer().gainMesos(-1);
} else {
cm.sendOk("You do not have 1 meso.");
}
cm.dispose();
}
}




You can criticize if you wish.
Explanation of Global Variables:
A Global Variable is a variable that is declared outside a function, example:
PHP Code:

chicken = 4000252;
// Then function start() {
function start() {




Explanation of a Multi-dimensional Array:
An Array that can separate items. Example, you have 56 selections, but you wish to have it separated, like 26 items and 30 items on another array. Well, you can use this:
PHP Code:

array = [[itemid, so on so forth], [itemid, so on so forth.]]; // Okay.



To use a multi-dimensional Array, you have to use two [selection] tags. The reason why, is which array am i going to use, the 1st or second within the array? That's why. So example(Not entirely sure):
PHP Code:

cm.gainItem(array[selection][selection]);