Hi everyone I am new to javascript arrays and understand it just a little but need some help.
I have created an empty array name Numbers. I will use Numbers for all of my functions, therefore, I made it a global variable.

Then I created a function named FillArray. The purpose of this function is to get the last number out of the textbox and stick it into a variable called LastNumber.

When I get the "number" from the textbox, I need to convert it to a true number variable. Last but not least I need to use a while loop to fill the array with a bunchof numbers, starting with ) and ending with LastNumber.

This is what I have but I am not confident with it.

var Numbers = new Array();
var LastNumber;
var i;

var LastNumber = Numbers[Numbers.length-1];
function FillArray()
i = 0;
while (i < LastNumber) {
  document.frmMain.txtaOutput.value = (Numbers[i]);
  i = i + 1;
}

can someone explain to me what I am doing wrong and what I should do?

You are making a copy of the array with your function declaration. Then, when you return from the function, the copy is not copied back to the original.

Either address the array globally (don't use it as a paramet4er, but just use it inside the function), or return it in the return statement.

I am sorry I am not understanding, can you explain to me in simpier term. I am very new to this. What I am understanding, you are saying don't use Numbers which is my array in my function leave it alone globally right.

If that is what you are stating that is now what I done but it is not functioning.

You are making a copy of the array with your function declaration. Then, when you return from the function, the copy is not copied back to the original.

Either address the array globally (don't use it as a paramet4er, but just use it inside the function), or return it in the return statement.

Okay I been working with this code can someone tell me if I am doing it right?
This is what I am trying to do: I have created an empty array name Numbers. I will use Numbers for all of my functions, therefore, I made it a global variable.

Then I created a function named FillArray. The purpose of this function is to get the last number out of the textbox and stick it into a variable called LastNumber.

When I get the "number" from the textbox, I need to convert it to a true number variable. Last but not least I need to use a while loop to fill the array with a bunch of numbers, starting with 0 and ending with LastNumber.

var Numbers = new Array();
var LastNumber;
var len;
var i;


function FillArray()
len=document.frmMain.txtaOutput.value.length;
LastNumber=document.frmMain.txtaOutput.value.FillArray(len-1); 
{
i = 0;
while (i < LastNumber) {
  document.frmMain.txtaOutput.value = (Numbers[i]);
  i = i + 1;
}
}
This article has been dead for over six months. Start a new discussion instead.