1. The Set object

// Const set1 = new Set() set1.add(1) set1.add(2) console.log(set1) // Set(2) {1, Const set2 = new Set([1, 2, Add (4) set2.add(' Lin Sanxin ') console.log(set2) // Set(5) {1, 2, 3, 4, Log (set2.has(2)) // true // Check the length using size console.log(set2.size) // 5 // delete the element used Delete set2.delete(2) console.log(set2) // Set(4) {1, 3, 4, 'Lin SAN xin'}Copy the code

No repetitive

Different Pointers to objects cannot be de-duplicated
NaN will be de-duplicated
Const arr =,3,1,3,5 [1]; const arr1 = [...new Set(arr)]; / /,3,5 [1]Copy the code

2. The Map object

(Key-value pair) Key is not restricted by type
const map = =new map(); map.set(true,1); The map. The set (1, 2); map({},"ccc") console.log(map) // Map(3){true=>1, 1>2, {}=>"ccc"} map.has({}) //true map.get(true) //2 map.delete({}) // Map(2){true=>1, 1 > 2} / / the const array map = = new map ([[true, 1], [1, 2], [{}, "CCC"]]). // Map(3){true=>1, 1>2, {}=>"ccc"}Copy the code

3. For and in

for(let key in obj){}
for(let value of obj){}

Copy the code

4. The find and findIndex

  • Find Returns the found element. Could not find return undefined
  • FindIndex Returns the index of the element that was found
Const findArr = [{name: 'kobe, no:' 24 '}, {name: "rose", no: '1'}, {name: 'the radmanovic, no: '0'}] const kobe = findarr.find (({name})=> name = 'kobe '); Const kebeIndex = findarr.findIndex (({name})=> name = 'kirby '); Kobe {name: 'kobe ', no: '24'} kebeIndex // 0Copy the code

5. Deconstruct assignments

object

Const obj = {name:"bs", age:22, gender:" female ", doing:{morning:"fish", afternoon:"eating", evening:"sleep" } } const { name, age, genter } = obj; //name age genter //"bs" 22 "female" const {name: myName} = obj; //myName // "bs" const { doing: { evening }} = obj; evening // sleepCopy the code

An array of

Const arr = [1, 5, 7]; const {1:a, 2:b, 0:c} = arr; log a b c //5 7 1Copy the code

6.class

  • Use constructors to generate objects
Class Person {constructore(name) {this.name = name; } sayName() {console.log(this.log)}} const kobe = new Person(" kobe "); Kobe. SayName () / / kobe BryantCopy the code
  • class = function
  • The static static
  • The extend inheritance
class Animal {
    constructor(name,age) {
        this.name = name;
        this.age = age;
    }
}
class Cat extend Animal {
    say() {
        console.log(this.name, this.age)
    }
}
const cat = Cat("ketty",5);
cat.say() //ketty 5
Copy the code

7. Array method

7.1 Array. The forEach ()

  • Through the array
  • return undefined
Let arr [1, 2, 3, 4, 5]; ForEach (item,index arr) {console.log(item,index arr)} // 1 0 [1,2,3,4,5] 2 1 [1,2,3,4,5] 3 2 [1,2,3,4,5] 4 3 4 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] 5Copy the code

7.2 Array. The map

  • The original array is not affected
  • Return a new array
Const arr1 = [1, 2, 3, 4, 5]; const arr2 = arr1.map((item, i, arr)=> i * item) arr2 // 0 2 6 12 20Copy the code

7.3 Array. The filter

  • filter
  • Return a new array
Const arr = [1, 2, 3, 4, 5]; Const newArr = arr.filter(num=> num<4) newArr // [1,2,3]Copy the code

7.4 Array. Some

  • Checks if there are any conditions in the array that meet the requirements
  • return booloean
Const arr = [1, 2, 3, 4]; let res = arr.some(item=> item>2) res //trueCopy the code

7.5 Array. Every

  • Checks whether all required conditions are met in the array
  • return booloean
Let arr = [1, 2, 3, 4, 5]; let res = arr.every(item => item => 2); // false let res2 = arr.every(item => item => 0); // trueCopy the code

7.6 Array. Reduce

  • accumulator
Let arr = [1, 2, 3, 4]; const res = arr.reduce((pre,naxt)=> { return pre + next; },0) res // 10Copy the code

7.7 Array. Flat

  • The array dimension reduction
Const arr = [1, 2, 3, 4, [5, 6]]]. console.log(arr.flat(Infinity)); / / [6]Copy the code

7.8 Array. FlatMap

  • map + flat
Let arr = [" kobe James Anthony ", "Lillard Ross McCollum "]; / / / 'Bryant', 'James',' Anthony ', 'the Conrad', 'rose', 'McCollum] arr. FlatMap (item = > item. The split (''))Copy the code

8. Arrow function

  • Can’t be a constructor, can’t use new
  • Doesn’t have its own this
  • No Arguments object
  • Prototypeless object
const fn = name => {}

Copy the code

9.Object.keys

  • Gets the key collection of objects
} const keys = object. keys(obj) keys // ['name','age','gender']Copy the code

10. Template string

Const name = 'baisu '; const age = 22; Consoloe. log(' ${name} this year ${age} age ')Copy the code

11. Array extension operators…

// concatenate multiple arrays let arr1 = [1,2,3]; Let arr2 = (4 and 6); Let arr3 = [arr1,... arr2] the console. The log (arr3) / / [6] / / as a parameter function fn (name,... Params) {console.log(name,params)} fn(' params ',1,2,3); / / Perilla [1, 2, 3]Copy the code

12.includes

  • return boolean
Const arr = [1, 2, NaN]; console.log(arr.includes(NaN)); // TRUE console.log(arr.includes(NaN)); / / 1Copy the code

13. Exponentiation

Const num = math.h pow (3, 2); //9 //ES7 const num = 3 ** 2; / / 9Copy the code

14.Object.values

Const obj = {1: 'a', 2: 'b', 3: 'c',} the console. The log (Object) values (obj)) / / [1, 2, 3]Copy the code

15.Object.entries()

    1 : 'a',
    2 : 'b',
    3 : 'c',
}
console.log(Object.entries(obj)) // [ [1,'a'],[2,'b'],[3,'c'] ]

Copy the code

16. Data types

  1. Number
  2. String
  3. Object
  4. Boolean
  5. Undefined
  6. Null
  7. BigInt (greater than2^53 - 1The integer)
  8. Symbol (represents unique values)

17.? And??

  • ? Optional chain
const list = []; if (list? .length) { console.log("true"); } else { console.log("false"); //false }Copy the code
  • ?? The void merge operator

?? And | | the biggest difference is that in?? Only undefined and null are false values

Const a = 0 | | "beauty"; / / the beauty const b = "" | |" beauty ". / / the beauty const c = false | | "beauty"; / / the beauty const d = undefined | | "beauty"; / / the beauty const e = null | | "beauty". Const a = 0?? "Beauty"; //0 const b = "" ?? "Beauty"; // const c = false ?? "Beauty"; //false const d = undefined ?? "Beauty"; // const e = null? "Beauty"; / / the beautyCopy the code