JavaScript Memo Review notes 1

Source: Internet
Author: User

One. String manipulation

1. Case

var s = "Hello"= s.touppercase ();" HELLO "g;" HELLO "g.tolowercase ();" Hello
View Code

2. Indexing/Truncation

S.indexof (' o '); 4all.js:1 loading comments ... var l = "Hello World"; undefinedl.substring (0,5);" Hello "l.substring (7);" Orld "
View Code

Two. Arrays

1. Index/length

var NULL true ];undefinedarr.length; 6arr[2]=99; arr;[ NULL true]
View Code

2. Slicing

arr; [nulltrue]arr.slice (1,3); [2, 99]
View Code

3.pop/push and Shift/unshift (remove from scratch, insert from scratch)

 arr;[ 1, 2, 
   
    null , 
    ]arr.pop ();  
    true  
    arr; [ 1, 2, 
    
     null  
     ]arr.push (  1, "SD" 
      7arr;[ 1, 2, 
      
       null 
      , 1, "SD" 
     ]arr.unshift (  ' head ', ' sec ' 
      9arr;[ " Head "," SEC ", 1, 2, 
      
       null 
      , 1," SD "
      " Head "arr;[" SEC ", 1, 2, 
      
       null 
      , 1," SD "] 
    
   
View Code

4. Sort/Flip/Specify Index Delete

 var  arr = [1, 2, 3.14, ' Hello ', null , " Span style= "color: #0000ff;" >true  ];undefinedarr.sort (); [ 1, 2, 3.14, "Hello", null , true  Span style= "color: #000000;" >]arr.reverse (); [ true , null , "Hello", 3.14, 2, 1< Span style= "color: #000000;" >]  var  arr = [' Microsoft ', ' Apple ', ' Yahoo ', ' AOL ', ' Excite ', ' Oracle ' ];undefinedarr.splice ( 2, 3, ' Google ', ' Facebook '  "Yahoo", "AOL", "Excite" ]arr; [ "Microsoft", "Apple", "Google", "Facebook", "Oracle" ]arr.splice ( 2,2< Span style= "color: #000000;" >); [ Google, Facebook] 
View Code

5. Concatenation of arrays

arr; ["Microsoft", "Apple", "Oracle"]var lst = [' A ', ' B ', ' C '];undefinedvar lstadd = Arr.concat (lst); undefinedlstadd; ["Microsoft", "Apple", "Oracle", "A", "B", "C"]lstadd.join ('-');" Microsoft-apple-oracle-a-b-c "
View Code

6. Multidimensional arrays

Three. Objects

var xiaoming = {    ' xiaoming ',    1990,    ' Middle School ',     1.70,    n,    null};undefinedxiaoming.name;" Xiaoming "xiaoming[' name ']; inch xiaoming; true xiaoming.hasownproperty (' name '); true
View Code

Four. Cycle

1. Arrays

var arr = [' Apple ', ' Google ', ' Microsoft '];  for (var i = 0; I <= arr.length; i++) {    alert (arr[i]);}
View Code

2. List

var arr = ' Sdadda ';  for (var i = 0; I <= arr.length; i++) {    alert (arr[i]);}
View Code

3. Objects (Python-like dict)

var o = {    "Jack",    +,    ' Beijing '};  for (var in o) {    alert (O[key]);}
View Code

Five. Map/set (Map: Python-like dict)

1.Map Fetch Value

var New Map ([    [' Michael ',], [' Bob ', ' +], [' Tracy ', ' +]    ]); alert (M.get (' Michael '));
View Code

2.Map Increment/Delete value

var New Map (); M.set (' Alex ',M.set); (' Bob ', ' m ');alert (M.has (' Bob ')); Delete (' Bob '); alert (M.get (' Alex '));
View Code

3.Set (de-newlst, python-like List = Set (LST))

var New Set ([1, 2, 3]); undefineds2; Set {1, 2, 3}s2.add (4); Set {1, 2, 3, 4}s2. Delete (2); true S2; Set {1, 3, 4}all.js:1 loading Comments...s2.add (4); Set {1, 3, 4}
View Code

Six. iterators ( Array , Map and Set all belong iterable to types, with for: of iterations---ps:for. of is against for. In fix)

1.for.. Of

var a = [' A ', ' B ', ' C ']; var New Set ([' A ', ' B ', ' C ']); var New Map ([[1, ' x '],[' name ', ' y '],[3, ' Z ']]);  for (var  X of a) {    alert (x);}  for (var  X of s) {    alert (x);}  for (var  x of m) {    alert (x[0]+ ' = ' +x[1]);}
View Code

2.forEach

//ArrayvarA = [' A ', ' B ', ' C '];a.foreach (function(element, index, array) {//element: A value that points to the current element    //Index: Point to Current index    //array: Points to the array object itselfalert (element);});//Mapvarm =NewMap ([[1, ' X '], [2, ' Y '], [3, ' Z ']]); M.foreach (function(value,key,map) {alert (value); alert (key);});//Set no indexvars =NewSet ([' A ', ' B ', ' C ']); S.foreach (function(element, set) {alert (element);});
View Code

JavaScript Memo Review notes 1

Related Article

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.