And define the basic operation of the array javascript Detailed

An array is a collection of data, js, the array of data which can be
different types of

Define the array:

1. Create an array of instances of the class by
var alist01 = new Array (1,2,3) ;

2 to create the array by way of the amount of direct
        var alist02 = [1,2,3];

Array Operations

1 to obtain the number of array members by length
        Alert (alist02.length);

2. Get index array member by
        Alert (alist02 [0]);
3., POP method behind the array is increased by push, delete a member
        alist02.push ( 'Z');
        Alert (alist02);
        alist02.pop ();
        Alert (alist02);
4., in front of the array method of POP is increased by push, delete a member
        alist02.unshift ( 'Z');
        Alert (alist02);
        alist02.shift ();
        Alert (alist02);
5. the inverted array
        alist02 .reverse ();
        Alert (alist02);
6. the return values in the array position of the first occurrence of
        var alist03 =
[ 'a', 'B', 'C', 'D', 'a', 'B' ];
        Alert (alist03.indexOf ( 'B'));
7. the add or remove members in the array
        alist03.splice (1,0, 'z', 'x', 'y');
        // index of from 1, i.e., the second element start,
deleting 0 elements, increasing z, x, y three elements
        Alert (alist03);
8. The .join array into a string
        var alist03.join STR = ( "-");
        Alert (STR);

        Or alert (alist03.join ());

Guess you like

Origin www.cnblogs.com/zhongxiaoyan/p/11829379.html