javascript based learning 2

 Array
          var arr = new Array(2,1,5,6,7,4,9); 
          var arr2 is the Array = (1,2, "33 is");  // omitted new to create the array
          var ARR3 = [1,2, "33 is"];  // to create the array by a constant
          Math.random ();  // arbitrary number between 0 and 1.
          for ( var I in arr) {document.write (arr [I] + "");}  // iterate another arr manner. This method than for high cycle efficiency
        /* 
         1. Stack structure:
             push () method : From an inlet, from the same port. Features: last out. Function: add elements to the end of the array, 
                  alert(arr); 
                 var aes = arr.push("ee","sdfs"); 
                  alert (aes);  Return Value: After adding the element length of the array.
             pop () method : removing the last element
                  var An aes = arr.pop, (),; 
                 alert (aes);  Return Value: returns the last element just removed.
             Queue structure: Also an out of a feed, from the features: FIFO
             shift () method , an element is removed from the head of the array
             unshift () method , the head insert elements from the array
             the concat () ; combined array, the return value, a new array combined, arr.concat (arr2);
             Slice () ; cut list, returns the value, new array sheared, slice (1,3); the second and fourth elements removed index,
             splice () ; splice (subscript, length, element);
                 Delete Function splice (1,1);  removing the second length. 1,  var AM arr.splice = (1,1);  the return value to delete the second element,
                 Add Function splice (1,0, "SDF"); splice (1,0, "SDF", "DSF");  Start additive element from the second element
                 Alternatively Function splice (1,1, "sdfsd"); 
             the Join () ; break splicing, the splicing element to a string,  arr.join ( "+ S");  Return Value Returns a string

 

             Reverse () ; array in reverse order
             Sort () ; ascending order, the default is asc ii coding table to sort strings, not sorted according to size,

 

         2. The two-dimensional array
             1,2,3,4,5
            6,7,8,9,10
            
  var arr = [[],[],[],[],[]];
            var count = 0;每个数组中的元素
            var arr = [];
            for(i=0;i<5;i++){var newArr = []
                for(j=0;j<5;j++){newArr.push(++count);}
                arr.push(newArr);
            }
            alert(arr.length);//返回5
            alert(arr[0]);//返回1,2,3,4,5,

            for(i=0;i<arr.length;i++){
                for(j=0;j<=i;j++){document.write(arr[i][j] + "&ensp");}
                document.write(<br />);
            }

 

         Bubble Sort
           
   var arr4 = [9,4,8,6,7,2 ];
             for (I = 0; I <arr4.length; I ++ ) 
            { 
                for (J = 0; J <arr4.length -i -1; J ++ ) 
                { 
                    iF (arr4 [J]> arr4 [J +. 1 ]) whether the two numbers before and after exchange 
                    { 
                        var tmp = arr4 [J]; 
                        arr4 [J] = arr4 [J +. 1 ]; 
                        arr4 [J + 1'd ] = tmp; 
                    } 
                } 
            } 
            Alert (arr4);

 

         Selection Sort
            
  var arr4 = [5,6,4,7,3,9];
            for(i = 0;i < arr4.length;i++)
            {
                for(j = i;j < arr4.length  ; j++)
                {
                    if(arr4[j] < arr4[i])
                    {
                        var tmp = arr4[i];
                        arr4[i] = arr4[j];
                        arr4[j] = tmp;
                    }
                }
            }
            alert(arr4);

 

         Variable function scope
            
    var A = 10 ;
             function Show () { 
                A =. 5 ; 
            } 
            Show (); 
            Alert (A); // returns. 5 

            var A = 10 ;
             function Show (A) { 
                A =. 5 ; 
            } 
            Show (A); 
            Alert (A); // returns 10, released after the end of the parameter function call 

            var ARR = [1,2 ];
             function Show (ARR) arr.push {(3,4- );} 
            Alert (ARR); //Returns 1,2,3,4 array is a complex data type / types of reference data, is not stored in the function is stored in the stack segment, are complex data types of all the reference address

 

         Function strings : document.write must be used in
              var STR = "Hello"; str.charAt (2);  the subscript returned l. str [1];  it may not be assigned,  STR [. 1] = "X";  , only  str = "sdf"; 
             Big () ; with a large font,
             Blink () ; (IE incompatible) with flashing string
             Bold () ; bold
             Fixed () ; typewriter text display,
             Strike () ; strikethrough
             fontcolor();
             fontsize();
             Link (); Links
             sub();下标,  document.write("hello".sub()); 
             SUP (); superscript
            
             the charCodeAt (subscript); return asc ii code value
             fromCharCode (asc ii code value)
             concat();   
    var str = "1";
    var str2 = "2";
    var str3 = str.concat(str2);

 

         String search method:
             the indexOf () ; the indexOf (substring, start looking subscript) , the return value, the same position of the first occurrence of the string, or not -1
             lastIndexOf () ; lastIndexOf (substring); position after the first occurrence of the same string, the return value is not -1
             Search () ; regular expression parameter may be, I case insensitive, G represents the global match
                  var STR = "ABCABCABC"; str.search ( "ABC");  return 3, the regular expression / abc / i, returns 0
         String replacement:
             Replace () ; Replace (string matching / regular expression, "df"); return value, the replacement string,
             replace ( "are", "sdf "); features can only be found to replace the first goal
             replace (/ sf / g, " sdf"); replace all of the same string
             the substring ();  the substring (2,4);  taken subscript 2 and 3 do not include 4, the return value, generating a new string
             Slice ();  Slice (-2);  taken last two characters.
             Split (); Split (separator, resulting array); returns an array
              var STR = "the this IS IT"; var ARR = str.split ( "", 2);  length of the two arrays
            Conversion string array arr.join ( ""); Returns a string
             toLowCase (); all lowercase
             toUpperCase (); all uppercase

Guess you like

Origin www.cnblogs.com/solaris-wwf/p/11622200.html