Array add, delete method (push () - unshift () - pop () and Shift ())

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组增、删方法(push()-unshift()-pop()和shift())</title>
    <!-- 
        //Add to
        n.push (); adding an array value n, the value n is added last array is located
        n.unshift (); adding an array value n, the value of the added n array located foremost
            - When printing individual code block value, outputs colors.length, the entire array (i.e. the length of the array)
        //delete
        Deleting the last value of the array of n; () n.pop
        Remove the top of the array of n values; () n.shift
            - alone printing execution code block is deleted, the output value will be deleted
     -> 
</ head > 
< body > 
    < Script > 
        // Push 
        var Colors = [ " Red " , " Green " , " Blue " ];
         var A = colors.push ( " Black " ); // Push added value is in the rearmost colors 
        the console.log (colors);
        the console.log (A); // when printing single code block value, the output array will colors.length, (i.e., length of the array) 
        // the unshift 
        var the nums = [ . 1 , 2 , . 3 , . 4 , . 5 ];
         var B = nums.unshift ( - . 1 , 0 ); // value added unshift nums located foremost 
        the console.log (nums);
        the console.log (B); // when printing single code block value, the output array will colors.length, (i.e., length of the array)

        // POP 
        var X = [ . 1 , 2 , . 3 , . 4 , . 5 ];
         var Q = x.pop (); // POP delete the last value:. 5 
        the console.log (X);
        the console.log (Q); // separate print execution code block delete, print values are deleted:. 5 
        // Shift 
        var Y = [ . 1 , 2 , . 3 , . 4 , . 5 ];
         var W = y.shift (); // the Shift delete the foremost value 
        console.log (y);
        the console.log (W); // alone printing block of code to delete, print values are deleted:. 1 
    </ Script > 
</ body > 
</ HTML >

 

Guess you like

Origin www.cnblogs.com/vinson-blog/p/12006307.html