1, filter is also a common operation function, he is used for some elements of the array, and then return the remaining elements, and map () like, the array of filter () also accepts a function, and map () is different, filter () The function of the passed in to each element, It then determines whether to persist or discard the element, depending on whether it is true or false.
Filter () accepts the return function, in fact, can have more than one parameter, usually we only apply the first parameter, representing an element of the array, the return function can also accept the other two parameters, the location of the bird element and the array itself.
2. The sort () method of the array defaults to converting all the elements into string reordering,
3, the arrow function is equivalent to anonymous function, the arrow function has two kinds of formats,
4, regular expression, \d match a number, \w match a letter or a number
' 00\d '-----"007 ' \w\w '------>js
. Match any character
' JS. '------>jsp JSS js!
If the match gets longer characters, use the * number, which means any character (including 0), with + for at least one character, with the? Represents 0 or 1, with {n} representing n characters, with you {n,m} representing n to M characters
\s means match a space
[0-9a-za-z\_] can match a number or letter or underline
^
Represents the beginning of a row, ^\d
indicating that a number must begin.
$
Represents the end of a line, indicating that it \d$
must end with a number
3. You can use Location.herf to get the value of each part of the URL
Location.protocol, Location.host location.port location.pathname location.search Location.hash
A cookie is a key_value identifier that is sent by the server, because the HTTP protocol is stateless, but the server distinguishes between which user requests are made, and the cookie is used to differentiate When a user logs on to the server successfully, the server sends you a cookie to the browser, listed as User=nsdnf9030-23r0 .... When the browser accesses the website, the cookie server is appended to the request header to differentiate the user from the cookie.
In addition, cookies can store some settings of the website, document. Cookies
4, the History object has saved the browser historical record, JavaScript can call the history's back () or forward (), this object belongs to the historical legacy object, for the Web page, uses the massive AJAX interactive page,
5, the operation of the DOM node, through a variety of ways to get DOM nodes, common methods document.getElementById () and Document.getelementbytagname (), and CSS selector document.getelementbyclassname ();
6, when we get the DOM, if the DOM is empty, you can directly use innerhtml= ' <span>child</span> ' to modify the DOM's node content, equivalent to inserting a new DOM node, but if the DOM node is not empty, You cannot use this method because innerHTML will replace the original node directly,
Use AppendChild to add a node to the parent node and the last child node.
7. JavaScript processing Form
<form id= "Test-form" >
<input type= "text" name= ' test ' ><button type= "button" onclick= "Dosubmitform ()" >Submit</button>
</form> <script>
Fuction Dosubmitfrom () {
var Form=documnet.getelementbyid (' Test-form ');
Form.submit ();
}</script>
1. Filter out inherited attributes
To filter out the properties of an object's inheritance, use it hasOwnProperty()
to implement:
var o = { name: ‘Jack‘, age: 20, city: ‘Beijing‘};for (var key in o) { if (o.hasOwnProperty(key)) { console.log(key); // ‘name‘, ‘age‘, ‘city‘ }}
2. Because array is also an object, and the index of each of his elements is considered an attribute of the object, the for ... in loop can directly loop out the index of the array, but note that the loop result is the southern type of s on the same day.
var a=[' A ',' B ',' C ']; for (var i in a) { Consloe. log(i); console. Log(A[i]); }3, Map is a key-value pair similar to array
Since a key can only correspond to one value, the value is placed on a key multiple times, and the face will flush out the previous values.
4, set and map similar, but also a set of key set, but do not store value because key cannot be duplicated, there is no duplicate key in set, to create a set, you need to provide an array as input, or directly create an empty set
var s1=new Set ();
var s2=new Set ([+]); Repeating elements are automatically filtered in set,
Use for ... the Loop traversal collection, but the best Korean uses the Foreach method in the Iterable function, which accepts only one function, and each iteration automatically recalls the function.
Iterable
Since JavaScript allows you to pass in any parameter without affecting the call, it is no problem to pass in a parameter that is more than the one you define, even if you don't need those calls inside the function.
ABS (, ' Blablabla ');//Return to ABS ( -9, ' hahaha ', ' Mjsds '), return 9
With arguments, you can get all the arguments passed in by the caller, that is, even if the function doesn't define any parameters, you can get the value of the parameter.
In order to obtain a parameter other than the already defined parameter, the arguments is used, and the loop is to reject the previous parameter, and the rest parameter can be used to solve the
function foo (A, b,..... rest) {
Console.log (' a ' +a);
Consloe.log (' B ' +b);
Consloe.log (rest);} Foo (1,2,3,4,4), but the rest parameter can only be written in the last
Use in front of ... identification, the parameters passed in first bound A, a, a number of parameters, in the form of an array to the variable rest so no longer use arguments, you can directly get all the parameters
Because JavaScript functions can be nested, an intrinsic function can access the bianl defined by an external function, which in turn does not
No statement var x= ' Hello ' +y; The reason is that the variable y is declared, but Console.log () shows Hello, undefined the value of 0 y is undefined, This is because the JavaScript engine automatically promotes the declaration of the variable y, but does not raise the assignment of Y
So it's common to start declaring arguments to the object, using Var
function foo () {
Var
x=2;
y=x+1;
Z;i;
for (i=0;i<100;i++) {
。。。。。。。 }}
5, on the AV is the default has a global variable window, the global scope of the variable is actually bound to a property of widow, the output is the same as the result is the same
A function defined as a variable is var foo = function () {}
actually a global variable, so the definition of the top-level function is also treated as a global variable and bound to an window
object:
JavaScript actually has only one global variable scope, any variable if not found in the current function will continue to find in the previous layer, and finally in the global variable also has, will be reported Referenceerror
6, the function bound to the object is called a method, and the function is not different, but he used a keyword inside this,this only a special variable, which points to the current object, as follows, xiaoming this variable, so, This.brith can get the birth property of Xiaoming
length
JavaScript notes Collation