Big_Al
February 22, 2003, 10:39pm
1
Is there a way to add a value to a preexisting array? I am by no means an actionscript expert so if you know could you try to explain it as simply as possible? Or is this function already simple and I just havent found it?
Many thanks to any who can help.
system
February 22, 2003, 11:01pm
2
It is called push()
Try this…
myArray = ["a", "b"];
myArray.push("c");
trace(myArray);
The original array only has “a” and “b”, but the push adds “c”, so the output in the window should be “a,b,c” (no quotes)
system
February 22, 2003, 11:26pm
3
Push adds the value at the end of the array. Unshift adds the value at the begining of the array:
myArray1 = ["1", "2"];
myArray2 = ["1", "2"];
myArray1.unshift ("3");
myArray2.push ("3");
trace ("myArray1 = " + myArray1);
trace ("myArray2 = " + myArray2);
//Outputs:
// myArray1 = 3,1,2
// myArray2 = 1,2,3
just FYI
Cheers,
jubs :rambo:
system
February 22, 2003, 11:30pm
4
Ah, didn’t think about adding to the FRONT of the array… good catch there Jubba