2018-06-15for with arrays/for-in and arrays/one-dimensional two-dimensional multidimensional arrays

Source: Internet
Author: User
Tags array length array to string

For loop can be ++i from 0, can also from the largest number, has been-I, can!!!

A For loop is nested inside a For loop:

Outside the ++i into the inside, inside the for loop after a cycle, in the jump to the outside, continue to ++i!

(Parent for loop one number, child for loop one cycle)

The same code needs to be copied and pasted, that is, the code needs to be optimized!

Set a small goal: Important code stick to write comments, density of about 3 lines one!

Array Meaning: A collection of many data (values/variables)!

Define à action (add modification) à use

var arr = []; --Define the way (generally using the same data type)!

Array elements: Each value in [] is called an array element!

Array subscript (Index): The position of the specified array element in the array (note that it starts at 0)!

Array Length: Number of array elements (ARR.LENGTH)!

Take the array element: arr. [Array subscript]

Arr.push= (arr.length);

--Add an array element of array length (plus the previous length is a few, this array element is a few)!

After the development of code, the value of the variables may not be known, the variables stored in what data must be clear!!!

Console.log (Shuzu[shuzu.length-1]);

--Always output the last variable (shuzu.length-is not possible, only can-number)!

Join ()//array to string
Add Delete for push () and pop ()///End
Shift () and unshift ()//Add Delete for first element
Sort ()//Sort (1 3 2 4à1 2 3 4)
Reverse ()//Invert
Concat ()//connection array ([1,2][3,4]à[1,2,3,4])
Slice ()//delete the element at the specified position
Splice ()//delete the element at the specified position
IndexOf () and LastIndexOf ()//Find element (this element is not inside this array, if in, returns a subscript)!

Array traversal: Take out every number in the array to do something (make a visit and do it only once)!

For and array traversal

For-in and Array traversal

One-dimensional arrays/two-D arrays/multidimensional arrays!

2018-06-15for with arrays/for-in and arrays/one-dimensional two-dimensional multidimensional arrays

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.