JAVASCRIPT ARRAY OBJECT

The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Syntax:
Use the following syntax to create an Array object −
var fruits = new Array( "apple", "orange", "mango" );

Properties:
1.length- Reflects the number of elements in an array.
2.constructor- Returns a reference to the array function that created the object.
3.prototype- The prototype property allows you to add properties and methods to an object.

Methods:
1. concat()-Returns a new array comprised of this array joined with other array(s) and/or value(s).
2. join()-Joins all elements of an array into a string.
3. indexOf()-Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
4. lastIndexOf()-Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.
5. pop()-Removes the last element from an array and returns that element.
6. push()-Adds one or more elements to the end of an array and returns the new length of the array.
7. reverse()-Reverses the order of the elements of an array -- the first becomes the last, and the last becomes the first.
8. sort()-Represents the source code of an object

No comments:

Post a Comment