Branch, arrays

First, the branch statement presentation

1. Logic branches (conditional branch)

Programming a configuration
sequence structure: executing code from the downward order is
selected (branch) structures: Depending on the situation, executing code corresponding
loop structure: Repeat a thing
except for the structure of the sequence, the other two of the flow of the program structure control statements to achieve.
Selection (branch) structure of a program implemented by a conditional branch statement.

Two, if statements

1. conditional branch statement

 Two branch statement can not be represented three cases.

After the else statement plus an if statement into three branches, also known as multi-branch statement.

Single branch statement:
there is only one branch of a conditional statement. No else block if statement is a single branch.

 

switch statement

 

  

values and switch expression case expression compared two values are equal to the corresponding case of performing branching statements. Branch statement may have had as many, if not equal to any value of the switch expression case expression to perform default default branch statement.
2. Because the switch statement does not automatically quit After execution of the branch statement, will continue to perform the subsequent branch statement, which called the switch through to
avoid the penetration, we need to add break after each branch statement, out of the switch statement.

Array

1. Create an empty array

 

2, join () (the original array unchanged)

 String, by default Comma Separated Values

 

3. the Push () and pop () (the original array change)

push (): the length of the array receive any number of parameters, to add them to the end of the array by one, and returns modifications.
pop (): remove the last one end of the array, reducing the value of the array length, and returns the removed item. ,

 

 

 

 4.shift () and unshift () (the original array change)   

shift (): Delete the original first array, and returns the value of the removed element; empty array returns undefined;
The unshift (): add parameters to the beginning of the original array, and returns the length of the array.

 

5.sort () (the original array change) Sort

 

6. The splice () (the original array change)

Delete: Delete any number of items, simply specify two parameters: the number of items to be deleted and the position of the first item to be deleted.

 Insert: insert a specified position to an arbitrary number of items, providing only three parameters: starting position 0 (the number of items to be removed) and the items to be inserted.

 Alternatively: insert any number of items to the designated position, and delete any number of items by specifying three parameters: the starting position, the number of items to be inserted and any number of entries to be removed. Several inserted not necessarily equal to the number of items removed.

 

 7.reverse () (the original array change) Flip

 

 

 8.concat

Connecting two or more arrays

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/yang1997/p/11830826.html