Operation of the array

Source: Internet
Author: User

Methods for manipulating arrays (functions):

(common) push () adds a new element from the tail operation is the original array

Pop () deletes an element from the tail

Unshift () Adding elements from the beginning

Shift () removes an element from the beginning

Slice (start, end) gets some elements in the array, returns a new array, and intercepts the end subscript from the start subscript position (without containing the element where the end subscript is located)

Join (string) joins the elements in the array into strings and returns. If join () does not give arguments, separated by commas, or, if given arguments, delimited by the specified delimiter, forming a string return

Splice (start, length) starts from the array start position and deletes length elements. The direct operation is the original array

Common Splice (start, length, element 1, Element 2:) starts from the start position, replacing the corresponding length element as element 1, Element 2 ...

(common) IndexOf () returns the position of the specified element in the array at the first occurrence of 2. Search backward from the specified position, and the corresponding subscript is returned; no return-1 is found

(common) sort () array sort sorted in ascending order of ASCII corresponding values

To sort by numerical numeric size, you need to pass a function that sets the collation as the parameter score is the array to sort

Score.sort (function (x, y) {

return x-y;

});

Console.log (score);

// use Forin when you need to traverse an object

Defining objects

var dog = {

//Key (key) value pair form

Name: "Husky",

age:3,

color: "Gold"

};

For (k in dog) {

console.log (k, dog[k]);

}

Operation of the array

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.