12 Practical Javascript tricks for kinky sex

Source: Internet
Author: User

Here are 12 useful Javascript tricks to share . 16 years after JavaScript was born in 1995, countless web pages around the world rely on her for mission-critical tasks, andJavaScript has ranked 8th in the list of programming languages published by Tiobe, followed by C #, JavaScript has shifted from a previously decorative scripting language to a mainstream programming language that people use to develop larger and more complex programs.

1. Turn the rounding into a numerical type:

' 10.567890 ' |

Results: 10

' 10.567890 ' ^0

Results: 10

-2.23456789|0

Results: 2

~~-2.23456789

Results: 2

2. Date to Value:

var d = +new Date (); 1295698416792

3. Class Array Object goto array:

var arr = [].slice.call (arguments)

4. Beautiful Random Code:

Math.random (). toString (+). substring (2); 14-bit Math.random (). toString (+). substring (2); 11 Guests

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. Use 0 full-complement digits:

function Prefixinteger (num, length) {  return (Num/math.pow (ten, length)). toFixed (length). substr (2);

7. Exchange Value:

a= [B, b=a][0];

8. Insert 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 the array element:

var a = [1,2,3,4,5];a.splice (3,1);

10. Quickly take the maximum and minimum values of the array

Math.max.apply (math, [])//3math.min.apply (math, [])//1

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. Determine IE:

var ie =/* @cc_on [email protected]*/false;

12 Practical Javascript tricks for kinky sex

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.