16. Abbreviations for switch

Switch (data) {case 1: test1(); break; case 2: test2(); break; case 3: test(); break; // And so on... } var data = {1: test1, 2: test2, 3: test}; data[something] && data[something](); Or the or const data = new Map ([[1, () = > {the console. The log (' test1 ')}], [2, () = > {the console. The log (' test2 ')}]]). console.log(data.get(1)())Copy the code

16. Use the arrow function to return implicitly

Function getAge(age) {return 2 * age} const getAge = diameter => (2 * age)Copy the code

17. Function default parameters

Function add(test1, test2) {if (test1 === undefined) test1 = 1; if (test2 === undefined) test2 = 2; return test1 + test2; } add = (test1 = 1, test2 = 2) => (test1 + test2); add() //output: 3Copy the code

18. Assignment of the same key-value pair to the object

// const name = 'kay'; const age = 12; Const info = {name: name, age: age} const [age,name] = [12,'kay'] const info = {name, age}Copy the code

19. Deconstructing assignment abbreviations

// Const test1 = this.data.test1; const test2 = this.data.test2; const test2 = this.data.test3; Const {test1, test2, test3} = this.data; // Const {test1, test2, test3} = this.data;Copy the code

20. Objects convert arrays

const data = { test1: 'abc', test2: 'cde', test3: 'efg' };
const arr = Object.entries(data);
console.log(arr);
/** 打印:
[ [ 'test1', 'abc' ],
  [ 'test2', 'cde' ],
  [ 'test3', 'efg' ]
]
Copy the code

21.Object.values()andObject.keys()

const data = { test1: 'abc', test2: 'cde' };
const val = Object.values(data);
const key = Object.keys(data)
console.log(val)     // ['abc','cde']
console.log(key)     // ['test1','test1']
Copy the code

Find the largest and smallest values in an array

const arr = [1, 2, 3]; Math. Max (... arr); / / 3 Math. Min (... arr); / / 1Copy the code

23. Repeat a string multiple times

let test = ''; 
for(let i = 0; i < 5; i ++) { 
  test += 'test '; 
} 
console.log(str); // test test test test test 
//shorthand 
'test '.repeat(5);
Copy the code

Class array to array

Let arrayLike = {0: 'Tom', 1: '65', 2: 'male', 3: [' Jane ', 'John', 'Mary'], 'length' : 4} let arr = Array. The from (arrayLike) console. The log (arr) / / [' Tom ', '65', 'male' [' Jane ', 'John', 'Mary']]Copy the code

Continue to summarize and update, thank you for your attention