Entry
Is there a way to replace an array item? Can I make an array list out of variables, for example?
Aug 20th, 2001 02:02
Jean-Bernard Valentaten, Mike Barone,
Well, there's a lot of things you can do with an Array.
Basically Array is an Object of it's own in js and has it's own methods
and properties.
Here's a short list:
Props:
length - The ammount of items an Array has
Methods:
concat() - concatenates two Arrays (someArray = someArray.concat
(anotherArray);)
join() - turns an Array to a String, (myString = someArray.join(",")
returns something like "1,2,3,4")
pop() - deletes the last element of an Array and thus changes it's
length
push() - the opposite of pop(), returns the newest element (lastElement
= someArray.push("newElement", "newElement2", ...))
reverse() - reverses the elements of an Array (myArray = new Array
("1", "2"); myArray.reverse(), the content of myArray is now ("2", "1"))
shift() - deletes the first element of an Array and returns it
slice() - extracts a certain ammount of elements of an Array, returns a
new Array, the Arguments given are the first and the last element you
want to extract.
splice() - inserts one or more elements into an Array, the first
argument is the position where the insert starts, the secont is the
ammount of elements, the next arguments are the elements to insert.
sort() - sorts an Array
unshift() - inserts new elements at the beginning of the Array, then
returns the new length of the Array
That's just a brief introduction. If you wish to know more about Arrays
in js, read the manual.
HTH