typeof operator: Returns a string, which may be one of "undefined", "boolean", "string", "number", "object", and "function", so the array cannot be judged.
NaN (Not a Number): Usage NaN (val) If val can be converted into a number, it returns false, otherwise it returns true.
parseInt(val, way), where way can be 2, 4... It is to convert according to this division, return number type, num.toString(way) the same way, but return string type.
The object type has a hasOwnProperty(name) to determine whether the current object is in an instance or in a prototype.
Each function has an arguments attribute object to record its parameters, which is equivalent to an array of parameters. It can be recursive with arguments.
The unshift method can push two elements into the array from the front end and return the length. Unshift and pop can reversely simulate the queue.
sort(compare), where the compare(val1, val2) method returns -1 before val2 and returns afterwards, 0 seems to remain unchanged.
Use the splice function for array operations, splice(a1, a2, a3......) a1, a2 requires a1 to represent the starting position, a2 indicates the number of items to be deleted, and the following parameters represent the new value to be inserted from this position.
indexOf returns the position of a val in the array, and lastindexOf() starts from behind.
Iterative method of array: every() returns true only when each value returns true, filter() returns all arrays that return true elements, forEach() just runs the function, does not return, map() returns an array composed of the result of the function call, some() is opposite to every, if there is a return ture, it returns true.
For example: var everyRes = number.every(function(item,index,array){return item>2 ;}) ;//item,index,array three parameters are required.
Combination of arrays: reduce and reduceRight(), for example: var sum = values.reduce(function(prev,cur,index,array){return prev+cur;}); prev represents the previous one, cur represents the latter one.
Date type: var date = new Date(Date.parse("May 25,2004")); var date = new Date(Date.UTC(2015,4,5,17,55,50));
The first difference between call and apply is this (context object).
var obj =eval("("+data+")") to convert json, JSON.parse(data) is also OK. The difference between the two is that eval is equivalent to parsing the content as js, while parse is only converted into obj objects.
The corresponding JSON.parse is the JSON.stringify method to turn obj into json
To determine whether an object is an array: Object.prototype.toString.call(o) == '[object Array]' ;
How to use continue to break to break (also applicable to break):
var num = 0 ;outer:for(var i=0;i<10;i++) for(var j=0;j<10;j++) { if(i==5&&j==5) { continue outermost ; } num++ ; }alert(num);//95with statement:
var obj = { search : "st" , name : "lala", url : "www.VeVB.COM"} ;with(pbj){ var a = search ; var b = name ; var c = url ;}use
Object.defineProperty(obj,"key",{
configurable:true,
value:"value"
});
This allows the object's properties to be read-only.
Use Object.defineProperties to add multiple properties at once
Object.defineProperties(book,{ _year:{ value:2004 }, edition:{ value:1 }, year:{ get:function(){ return this._year ; } set:function(newValue){ if(newValue>2004) { this._year = newValue ; edition++ ; } } } } } }) ;The above is the full content of the js learning stage summary (must-read article) brought to you by the editor. I hope everyone will support Footstep Home more.