Seventh Chapter-javascript Arrays

Source: Internet
Author: User

7.1 Arrays

①javascript arrays are used in many ways, and elements in an array do not have to be exactly the same type

Two ways to construct a ② array:

A. Constructors for arrays

var arrayname=new array ()///empty array var arrayname=new array (4)/////Length 4 array var arrayname=new array ("Thomas", "Roger",-3, " Plastic "); Array of 4 elements

B. Array literals notation

var arrayname=[];//empty array var arrayname=["Thomas", true,-3];//three elements of an array var arrayname=[3];//an array of elements

7.2 Properties of an array (because the array is an object in JavaScript, it has properties and methods)

This is just a description of the length property, which is described in the other sections later.

var stu=["Thomas", "Roger", "Amber", "Jen"];stu.length=2;//shorten the array, now the array has only the first two elements stu.length=7;//an array of growth, adding 5 elements at the end, Their values are undefined. Stu[9]= "Mary";//increment array, length 10, index 9 that is, tenth element value is Mary, others are undefined

7.3 Methods of arrays

①sort method

②concat () method

③slice (Start,stop) method: Gets an array of sub-arrays, custom start and end indexes, sub-arrays include start index, no end index.

④splice (Start delete index, delete element number, [added element]) method

var arr=["Orange", "apple", "pear", "Grape"];var arr1=arr.splice (2,1, "watermelon", "plum"), arr1=["Orange", "Apple", " Watermelon "," plum "," grape "];

Seventh Chapter-javascript Arrays

Related Article

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.