JavaScript rhyme appreciate some of the classic JS code _javascript tips
Source: Internet
Author: User
1. The simultaneous conversion into numerical type:
' 10.567890′|0
Results: 10
' 10.567890′^0
Results: 10
-2.23456789|0
Results:-2
~~-2.23456789
Results:-2
2. Date Turn value:
var d = +new Date (); 1295698416792
3. Class Array object to an array:
var arr = [].slice.call (arguments)
4. Nice random code:
Math.random (). toString. substring (2); 14-bit
Math.random (). toString. substring (2); 11-bit
5. Merging 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. Full digit by 0:
function Prefixinteger (num, length) {
Return (Num/math.pow (length)). toFixed (length). substr (2);
}
7. Exchange Value:
a= [B, b=a][0];
8. Inserts an array into another array at the specified location:
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 take the maximum and minimum value of the array
Math.max.apply (Math, [1,2,3])//3
Math.min.apply (Math, [1,2,3])//1
(Originating from http://ejohn.org/blog/fast-javascript-maxmin/)
11. Conditional Judgment:
var a = b && 1;
Equivalent
if (b) {
A = 1
}
var a = B | | 1;
Equivalent
if (b) {
A = b;
} else {
A = 1;
}
12. Determine IE:
var ie =/* @cc_on!@*/false;
Do you have any more? Welcome to the response
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.