One side

Data type judgment

Obejct.prototype.toString.call([])//[Object Array]
Array.isArray([])//true
[].constructor === Array//true
[] instanceof Array//true
typeof ' '//string
Copy the code

Array to heavy

let nums = [1.2.3.4.4];
let newNums = new Set([...nums]);
function noRepeat(nums){
    let target = [];
    nums.forEach(element= >{
        if(target.indexof(elelment)===-1){
        target.push(element)
        }
    })
}
Copy the code

Arrays and objects in arrays are de-duplicated

Es6 new features

  1. Let, const
  2. Template string
  3. Arrow function
  4. Function parameter default value
  5. Spread/Rest operator (…)
  6. Binary and octal literals
  7. Object and array deconstruction
  8. Class class
  9. for… In and for… of

A JavaScript method that iterates over an object

  1. for... inIt also gets the properties on the prototype chain of the object
const obj = {
    id:1.name:'zhangsan'.age:18
}
for(let key in obj){
    console.log(key + The '-' + obj[key])
}
Copy the code
  1. Keys (obj)/values (obj)
constobj = {id:1.name:'zhangsan'.age:18
}
console.log(Object.keys(obj))//['id','name','age']
console.log(Object.values(obj))//['1','zhangsan','18']
Copy the code
  1. useObject.getOwnPropertyNames(obj)

Returns an array containing all properties of the object itself (including non-enumerable properties)

const obj = {
    id:1.name:'zhangsan'.age:18
}
Object.getOwnPropertyNames(obj).forEach(function(key){
    console.log(key+ The '-'+obj[key])
})
//id---1 name---zhangsan age---18
Copy the code

Promise specification

  1. Promise has three states:pending.fulfilled, orrejected; “Specification Promise/A+ 2.1”
  2. When you make a new promise, you need to pass oneexecutor()Actuator, actuatorExecuted immediately;
  3. Executor takes two arguments, one of which isresolveandreject;
  4. The default state for promise ispending;
  5. There’s one promisevalueThe value of the saved status, which can beundefined/thenable/promise; “Specification Promise/A+ 1.3”
  6. There’s one promisereasonSave the value of the failed state; “Specification Promise/A+ 1.5”
  7. Promise only frompendingtorejected, or frompendingtofulfilledOnce the state is confirmed, it will not change;
  8. There must be a promisethenMethod,thenReceive two arguments, one for the promise’s successful callbackonFulfilled, and the promise failed callbackonRejected; “Specification Promise/A+ 2.2”
  9. If the promise has been successful by the time then is called, it is executedonFulfilledThe argument is promise’svalue;
  10. If the promise has failed by the time then is called, it is executedonRejectedThe argument is promise’sreason;
  11. If an exception is thrown in then, it is passed as an argument to the failed callback of the next THENonRejected;

Realize the Promise. All

The role of # in the URL

# in the URL specified is a location in a web page Well, as a locator page appears in the URL, for example: www.httpwatch.com/features.ht… , this URL represents the location of print on the page features.htm. When the browser reads the URL, it automatically scrolls the print location to the visible area.

Special URL characters need to be escaped. 1. Replace Spaces with plus signs (+). 2. Separate URL and query 4. Percent sign (%) Specify special characters 5. # sign specifies bookmark 6

Principles of the VueRouter Hash mode and history mode