js Learning Stage Summary of Required Papers

  • 2021-06-28 10:59:03
  • OfStack

typeof operator: Returns a string, possibly one of "undefined", "boolean", "string", "number", "object", "function", so the array cannot be determined.

NaN (Not a Number): Usage NaN (val) Returns false if val can be converted to a number or true otherwise.

parseInt (val, way) in which way can be 2,4... is to convert according to this binary, return number type, num.toString (way) the same, but return string type.

The object type has an hasOwnProperty (name) to determine whether the current object is in an instance or a prototype.

Each function has an arguments attribute object to record its parameters, which is equivalent to an array of parameters, and can be recursively used with argumentscallee.

The unshift method pushes two elements from the front to the array and returns the length, while unshift and pop can reverse-simulate the queue.

sort (compare), in which the compare (val1, val2) method returns -1 before val2 and 0 after val1, as if it were unchanged.

For array operations, use the splice function, splice (a1, a2, a3...) a1, a2 required a1 for the starting position, a2 for the number of items to be deleted, and the following parameters for new values to be inserted from that location.

indexOf returns the position of an val in the array, with lastindexOf () counting from the end.

Iteration method for arrays: every() returns true for each value, filter() returns all arrays returning true elements, forEach() only runs functions, does not return, map() returns an array of function calls, some() is relative to every, and true is returned for one return ture.

Example: var everyRes = number.every (function (item, index, array){return item > 2;}; //The item, index, and array parameters are required.

Merge of arrays: reduce and reduceRight(), for example: var sum = values.reduce (function (prev, cur, index, array){return prev+cur;};prev stands for the first and cur for the last.

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) can also, the difference is that eval is equivalent to resolving content as js, while parse is only converted to obj objects.

Corresponding to JSON.parse is the JSON.stringify method, which converts obj to json

Interpret whether an object is an array: Object.prototype.toString.call (o) =='[object Array]';

How to jump out of a two-tier loop with continue (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);//95

with statement:


var obj = {
    search : "st" ,
    name : "lala",
    url : "www.ofstack.com"
} ;
with(pbj){
  var a = search ;
  var b = name ;
  var c = url ;
}

use

Object.defineProperty(obj,"key",{

configurable:true,

value:"value"

});

This allows the properties of the object to be read-only.

Multiple attributes can be added once with Object.defineProperties


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++ ;
              }
         }
        }
    }
}) ;

This is the whole content of the js learning phase summary (must-see article) that this site brings to you. I hope you can support the footsteps home more.


Related articles: