JavaScript Array Object

Source: Internet
Author: User
Tags javascript array

1. Push Method (Array)

Appends a new element to an array and returns the new array length.

Arrayobj.push ([Item1 [item2 [...] [Itemn]])

2. Pop Method (Array) ()

Removes the last element from the array and returns the element.

Arrayobj.pop ()


You can use the push and pop methods to simulate a stack that uses FIFO to store data.

The push method appends elements in the order in which they appear. If an argument is an array, it is added as a single element.

var Number;var my_array = new Array () My_array.push (5, 6, 7);//output array length 3, at this time my_array=[5, 6, 7]my_array.push (8, 9);//output array length is 5, at this time my_array=[5, 6, 7, 8, 9]number = My_array.pop ();//output value is 9while (number! = undefined) {document.write   );   Number = My_array.pop (); }//Output is 9 8 7 6 5


JavaScript Array Object Array Object

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

To create the syntax for an Array object:
New Array (); new array (size); new Array (element0, element1, ..., ELEMENTN);
Parameters

The parameter size is the expected number of array elements. Returns an array of length fields that will be set to the value of size .

Parameter element ..., elementn is a list of parameters. When you use these parameters to call the constructor array (), the elements of the newly created array are initialized to these values. Its length field is also set to the number of parameters.

return value

Returns the newly created and initialized array.

If you do not use parameters when calling the constructor array (), the returned array is empty and the length field is 0.

When the constructor is called, only one numeric argument is passed to it, and the constructor returns an array with the specified number and element undefined.

When an array () is called by another parameter, the constructor initializes the array with the value specified by the parameter.

When a constructor is called as a function, and the new operator is not used, its behavior is exactly the same as when it is called with the new operator.

Array Object Properties
Properties Description
Constructor Returns a reference to the array function that created this object.
Length Sets or returns the number of elements in the array.
Prototype gives you the ability to add properties and methods to an object.
Array Object method
Method Description
Concat () Joins two or more arrays and returns the result.
Join () Put all the elements of the array into a string. element is delimited by the specified delimiter.
Pop () Delete and return the last element of the array
Push () Adds one or more elements to the end of the array and returns the new length.
Reverse () Reverses the order of the elements in the array.
Shift () Delete and return the first element of the array
Slice () Returns the selected element from an existing array
Sort () Sorting elements of an array
Splice () Deletes the element and adds a new element to the array.
Tosource () Returns the source code for the object.
ToString () Converts the array to a string and returns the result.
toLocaleString () Converts the array to a local array and returns the result.
Unshift () Adds one or more elements to the beginning of the array and returns the new length.
ValueOf () Returns the original value of an array object


Http://www.w3school.com.cn/jsref/jsref_obj_array.asp






This article from "It Technology Learning and communication" blog, declined reprint!

JavaScript Array Object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.