JavaScript Basics Grooming (Occasional updates)

Source: Internet
Author: User

The definition of true and false in 1.js:

True: true, not 0 digits, non-empty string, non-empty object

False: False, numeric zero, empty string, empty object (null), undefined

2. Looping JSON using a for loop

For (var item in jsonobj) {

Alert (Jsonobj[item]);

3. Get non-inline styles (cannot get compound styles, such as background, need to clear a single style, such as BackgroundColor)

IE browser: obj.currentstyle[attr]

Chorme,firefox and other browsers: getComputedStyle (Obj,false) [attr]

4. Arrays Array operation

4.1 The Length property, which can be either obtained or set, can be used for array emptying, as shown below

    

4.2 Add:

Add from head: Unshift (x) added from tail: push (x)

4.3 Delete:

Remove from head: Shift () Delete from tail: Pop ()

4.4 Splice Method (also known as the universal operation of arrays)

Delete: Splice (index,length), from the starting position, delete the specified length of the element, as shown below

Added: Splice (index,length,x,y ... ), from the specified position, remove the length-setting element, and then add elements from the specified position, such as the following

4.5 Sort Sorts

Sort () can only sort strings by default, and if you sort directly on a numeric array, it is also treated as a string, such as the following

Array of strings:

Array of numbers:

To implement sorting of numeric arrays:

4.6 concat (ARR2) connection array, as shown below

4.7 Join (the connector), stitching the array elements into a string, as shown below

    

  

    

  

JavaScript Basics Grooming (Occasional updates)

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.