1. convert an integer to a numeric value at the same time:
'10. 567890 '| 0
Result: 10
'10. 567890 '^ 0
Result: 10
-2.23456789 | 0
Result:-2
~~ -2.23456789
Result:-2
2. date to numeric value:
Var d = + new Date (); // 1295698416792
3. convert a class array object to an array:
Var arr = []. slice. call (arguments)
4. Pretty random code:
Math. random (). toString (16). substring (2); // 14 digits
Math. random (). toString (36). substring (2); // 11 digits
5. Merge Arrays:
Var a = [1, 2, 3];
Var B = [4, 5, 6];
Array. prototype. push. apply (a, B );
Uneval (a); // [1, 2, 3, 4, 5, 6]
6. Use 0 to complete the full digits:
Function prefixInteger (num, length ){
Return (num/Math. pow (10, length). toFixed (length). substr (2 );
}
7. exchange value:
A = [B, B = a] [0];
8. insert an array to the specified position of another array:
Var a = [1, 2, 3, 7, 8, 9];
Var B = [4, 5, 6];
Var insertIndex = 3;
A. splice. apply (a, Array. concat (insertIndex, 0, B ));
// A: 1, 2, 3, 4, 5, 6, 7, 8, 9
9. Delete array elements:
Var a = [1, 2, 3, 4, 5];
A. splice (3, 1 );
10. quickly obtain the maximum and minimum values of the array.
Math. max. apply (Math, [1, 2, 3]) // 3
Math. min. apply (Math, [1, 2, 3]) // 1
(From http://ejohn.org/blog/fast-javascript-maxmin)
11. Condition judgment:
Var a = B & 1;
Equivalent
If (B ){
A = 1
}
Var a = B | 1;
Equivalent
If (B ){
A = B;
} Else {
A = 1;
}
12. Judge IE:
Var ie =/* @ cc_on! @ */False;
What else? Welcome to respond