JavaScript array (Array) Object

JavaScript Array (Array) Object

Effect object is an array: the use of a single variable name to store a series of values.

 

  • concat () method is used to connect two or more arrays

    This method does not change the existing array, but only returns a copy of the array is connected.

grammar

arrayObject.concat(arrayX,arrayX,......,arrayX)

 

parameter description
arrayX essential. The parameter may be a specific value, but may be an array of objects. It can be any number.

 

return value

Returns a new array. The array is obtained by adding all the parameters arrayX arrayObject generated. If you want to concat () is an array of operating parameters, adding that elements in the array, instead of an array.

 

            /*
            concat () method is used to connect two or more arrays.
            */

            /*
             Examples of a parameter concat () array is connected to a surname
            * / 
            Var Surname = [ "beam", "Yang", "have" ];
             var newSurname = surname.concat ( "Hu", "Law" );
             // var newSurname = surname.concat ([ "Hu", " Luo "]) the result of constant 
            console.log (" the original array: "Surname); // [" beam "," Yang "," have "] does not change the original array 
            console.log (" after connection array: "newSurname); // [" beam "," Yang "," has "," Hu "," Luo "]  


            /*
             Example 2 connecting two arrays
            * / 
            Var Surname = [ "beam", "Yang", "have" ];
             var surname2 = [ "Hu", "Luo" ];
             var newSurname = surname.concat (surname2);
            console.log ( "the original array:" Surname); // [ "beam", "Yang", "have"] does not change the original array 
            console.log ( "after connection array:" newSurname); // [ "beam", "Yang", "has", "Hu", "Luo"]  


            /*
             Example 3 connected to a plurality of arrays
            * / 
            Var Surname = [ "beam", "Yang", "have" ];
             var surname2 = [ "Hu", "Luo" ];
             var surname3 = [ "Chen", "bell" ];
             var newSurname = Surname. concat (surname2, surname3);
            console.log ( "the original array:" Surname); // [ "beam", "Yang", "have"] does not change the original array 
            console.log ( "after connection array:" newSurname); // [ "beam", "Yang", "has", "Hu", "Luo", "Chen", "clock"]  

 

 

 

 

  • join () method for all elements in the array into a string.

   Elements are separated by a specified delimiter.

grammar

arrayObject.join(separator)

 

parameter description
separator Optional. Specify the delimiter to be used. If omitted, a comma is used as a separator.

return value

Returns a string. The string is arrayObject by each element into a string, and then connecting these strings, interposed between the two elements of  separator  strings generated.

            /*
            join () method for all elements in the array into a string.
            */

            /*
             Example 1 array to a string, separated by commas
            * / 
            Var joinName = [ "beam", "Yang", "has" ];
            console.log (joinName.join ()); // Liang Yang, who 
            console.log (joinName); // [ "beam", "Yang", "have"] does not change the original array

            /*
             Example 2 array to a string, with "-" partition
            * / 
            Var joinName = [ "beam", "Yang", "has" ];
            console.log (joinName.join ( "-")); // Liang Yang, who

 

 

 

 

 

  • pop () method removes and returns the last element of the array.

grammar

arrayObject.pop()

 

parameter description
separator Optional. Specify the delimiter to be used. If omitted, a comma is used as a separator.

return value

The last element of arrayObject.

Explanation

pop () method removes arrayObject last element of the array length minus 1, and returns the value of its elements removed. If the array is already empty, the pop () array is not changed, and returns the undefined value.

            /*
            pop () method removes and returns the last element of the array.
            */

            var popName = [ "beam", "Yang", "has" ];
            console.log (popName.pop ()); // once (string) to delete the last element of the array 
            console.log (popName); // [ "beam", "Yang"] to change the original array length

 

 

 

 

reference:

https://www.w3school.com.cn/jsref/jsref_obj_string.asp

https://www.w3cschool.cn/javascript/js-obj-string.html

 

 

Guess you like

Origin www.cnblogs.com/Waiting-Liang/p/12426896.html