DAY- 15
JavaScript - The Arrays 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.
Ø Use the following syntax to create an Array object −
var fruits =newArray("apple","orange","mango");
Ø The Array parameter
is a list of strings or integers.
Ø When you specify a single numeric parameter with the
Array constructor, you specify the initial length of the array.
Ø The maximum length allowed for an array is
4,294,967,295.
Ø You can create array by simply assigning values as
follows −
var fruits =["apple","orange","mango"];
Ø You will use ordinal numbers to access and to set
values inside an array as follows.
fruits[0]is the first element
fruits[1]is the second element
fruits[2]is the third element
Array Properties
Ø The following is list of properties of the Array
object along with their description.
Property
|
Description
|
Returns a reference to the array
function that created the object.
|
|
index
|
The property represents the
zero-based index of the match in the string
|
input
|
This property is only present in
arrays created by regular expression matches.
|
Reflects the number of elements in
an array.
|
|
The prototype property allows you to
add properties and methods to an object.
|
Array Methods
Ø The following is the list of methods of the Array
object along with their description.
Method
|
Description
|
Returns a new array comprised of
this array joined with other array(s) and/or value(s).
|
|
Returns
true if every element in this array satisfies the provided testing function.
|
|
Creates a new array with all of the
elements of this array for which the provided filtering function returns
true.
|
|
Calls a function for each element in
the array.
|
|
Returns the first (least) index of
an element within the array equal to the specified value, or -1 if none is
found.
|
|
Joins all elements of an array into
a string.
|
|
Returns the last (greatest) index of
an element within the array equal to the specified value, or -1 if none is
found.
|
|
Creates a new array with the results
of calling a provided function on every element in this array.
|
|
Removes the last element from an
array and returns that element.
|
|
Adds one or more elements to the end
of an array and returns the new length of the array.
|
|
Apply a function simultaneously
against two values of the array (from left-to-right) as to reduce it to a
single value.
|
|
Apply a function simultaneously
against two values of the array (from right-to-left) as to reduce it to a
single value.
|
|
Reverses the order of the elements
of an array -- the first becomes the last, and the last becomes the first.
|
|
Removes the first element from an
array and returns that element.
|
|
Extracts a section of an array and
returns a new array.
|
|
Returns true if at least one element
in this array satisfies the provided testing function.
|
|
Represents the source code of an
object
|
|
Sorts the elements of an array
|
|
Adds and/or removes elements from an
array.
|
|
Returns a string representing the
array and its elements.
|
|
Adds one or more elements to the
front of an array and returns the new length of the array.
|
No comments:
Post a Comment
Give your valuable feedback