js common sense

1. In an array traversal 4

1.
for(var i = 0; i <arr.length; I++){
console.log(arr[i]);
}
2.
for(var index in arr){
console.log(arr[index]);
}
3.
for (var value of arr) {
console.log(value);
}
4.
arr.foreach (function (value, index // index value, arr) {
arr[index] = value*10;
})

2. Error Handling

try {
...
if () throw "custom error"
}
catch (e) {... //} abnormality Capture and Process
before finally {... // try and catch finally statement regardless whether an abnormality will be executed in the code block. }
 

3.cookie

1. Create a cookie
document.cookie = "username = John Doe; expires = <expires>" (in GMT or UTC time)
2. Read the cookie
var c = document.cookie;
3. Modify the cookie
Direct coverage on the line, and create the same
4. Remove cookie
document.cookie = "username = (value not set a cookie); expires = <previous time>."
 

4. Regular Expressions

1. / regular expression host / modifiers
 
2. ? Non-greedy
 
3. var r1 = / test / g; // equivalent to: var r2 = new RegExp ( 'test', 'g');
 
4. ^ represents a non-in []
 
5. ^ a | b $ a beginning and end are in line b
^ (A | b) $ a certain b
 

Guess you like

Origin www.cnblogs.com/fullmetalcoder/p/11587297.html
Recommended