Thursday, April 4, 2013

Javascript functions on the Array Object

The Array object is used to store multiple values in a single variable.


Syntax for creating an Array object:
var myCars=new Array("Saab","Volvo","BMW")

Array Object Properties
Constructor Returns a reference to the array function that created the object
index
input
Length Sets or returns the number of elements in an array
Prototype Allows you to add properties and methods to the object

Array Object Methods
Method
concat() Joins two or more arrays and returns the result
join() Puts all the elements of an array into a string. The elements are separated by a delimiter
pop() Removes and returns the last element of an array
push() Adds one or more elements to the end of an array and returns the new length
reverse() Reverses the order of the elements in an array
shift() Removes and returns the first element of an array
slice() Returns selected elements from an existing array
sort() Sorts the elements of an array
splice() Removes and adds new elements to an array
toSource() Represents the source code of an object
toString() Converts an array to a string and returns the result
unshift() Adds one or more elements to the beginning of an array and returns the new length
valueOf() Returns the primitive value of an Array object

No comments:

Post a Comment