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)