Record methods and knowledge points to avoid late forgetting
null and undefined
NULL represents a null value, undefined represents a value not defined.
= = and = = =
= = The data type is automatically converted and then compared. = = = Does not automatically convert the data type and returns False if the data type is inconsistent.
For example: false = = 0:true,false = = = 0:false
Array
var = new Array (Arry);
var array = [n/a];
Object
var model = {
Name: "Chenxy",
Age:20
}
Json
var model = {
"Name": "Chenxy",
"Hooby": ["Eat", "Play", "Game"]
}
Strict mode and global variables
If the variable is not declared with Var, it is considered a global variable. If there are more than one global variable with the same name, it will conflict.
To fix this problem, roll out the strict mode, such as an undeclared exception. The starting method is to add ' use strict ' to the JS code;
Escape character
\ nthe line, \ t tab, \ \ is \
String method
var ToUpper = strtext.touppercase (); Console.log ("all capitalization:" +ToUpper); var ToLower = strtext.tolowercase (); Console.log ("all lowercase:" +ToLower); var IndexOf = Strtext.indexof ("JQ"); Console.log ("returns the position where the specified character appears, if not-1:" +IndexOf) ; var SUBSTR = strtext.substring (0,3); Console.log ("returns the specified interval string:" +substr);
Array method
vararr = [10,20,30, ' 40 ']; varIndexOf = Arr.indexof (20); Console.log ("Returns the specified index if it is not-1:" +IndexOf); varSlice = Arr.slice (2,3); Console.log ("Intercepts some elements, returns a new array, and if you do not write the second one, the default is truncated to the last:" +Slice); Arr.push (50,60);//add several elements to the endArr.unshift (5,6);//add several elements to the headArr.pop ();//Delete last elementArr.shift ();//Delete First elementArr.sort ();//SortArr.reverse ();//ReverseArr.splice (2,3,80,90);//Delete three elements starting at index 2 and add two elements varARR2 = [' A ', ' B ', ' C ']; Arr.concat (ARR2); //merging two arraysArr.concat (1,2,[3,4]);//automatically take the array apart and combine varJoin = Arr.join ('-')); Console.log ("Each element is connected with the specified connector:" +join);
In operator
Queries whether an object contains a property. Contains true, and vice versa is false.
Example: ' name ' in obj;
Map and set
The structure of a set of key-value pairs with extremely fast lookup speeds. The key can not be the same name, if the same name will replace the previous
var New // initializing an empty map // Add a Smap.set ("B", +); Smap.has (// to determine if there is // get the corresponding value sMap. Delete// Remove key
The set does not have duplicate keys, and the repeating elements are automatically filtered. The rest is the same as map.
Arguments
All parameters that were passed in by the caller. Just write it in the direct way.
Rest
The extra arguments are given to the variable rest in the form of an array. Example: Function A (A, B,.. Rest) {}
This
Gets only the object that was called.
Apply to fix this point to object. Two parameters, the first one is the this variable that needs to be bound, and the second is the parameter. Example: Geta.apply (xiaoming,[1,2,3]); This points to xiaoming with a parameter of 123
Call is similar to apply, but is sequential input. Geta.call (xiaoming,1,2,3);
Decorative Device
With apply, you can rewrite the window's built-in methods. Example:
var oldparint = window.parseint; function () { alert (1); return oldparint.apply (null,arguments); }
Map
Iterating over an array allows each element in the array to execute a method. Cases:
function POW (x) { return x*x; } var arr = [1,2,3,4,5,6]; Arr.map (POW);
Reduce
The function must receive two values, iterate over the array, and perform an accumulative calculation. Cases:
function pow (x, y) { return x*y; } var arr = [1,2,3,4,5,6]; Arr.reduce (POW);
JavaScript Learning notes (i)