See a summary of ES6, feel good, here reprint, this is the original address, due to the blogger has their own photos, so I am not convenient to directly transfer:

Blog.csdn.net/qq_24147051…

Here are some of the most common optimization methods I use on projects

Var arr = [1,2,3,4,3,4]; var arr2 = […new Set(arr)]; In this case, arr2 is the deduplicated array ~

Let [x,y] = [1,2]; [y,x] = [x,y]; console.log(y); Let arr= “hellomybo”; console.log(arr[3]); 4- Use arrow function instead of callback ES5

Let a1 = [1,2]. Map (function (x) {return x * x; }); ES6 arrow function writing

Let a2 = [1,2]. Map (x => x * x);

console.log(a1,a2); Var arr1 = [‘a’, ‘b’]; var arr2 = [‘c’]; var arr3 = [‘d’, ‘e’]; // Merge array of ES5

arr1.concat(arr2, arr3); // [‘a’, ‘b’, ‘c’, ‘d’, ‘e’] // Merge array of ES6

[… arr1, arr2,… arr3] / [‘ a ‘, ‘b’, ‘c’, ‘d’, ‘e’] 6 – string reversal let STR = “12345678900987654321”; 1 Original writing:

Str.split (”).reverse().join(”)

[… STR].reverse().join(”)

[‘a’,’b’]. Filter (x => true) // [‘a’,’b’]

Let arr = [1, 2, 3, 4]. The map (x = > x + 1); console.log(arr); Var arr = [1, [[2, 3], 4], [5, 6]];

var flat = function* (a) { var length = a.length; for (var i = 0; i < length; i++) { var item = a[i]; if (typeof item ! == ‘number’) { yield* flat(item); } else { yield item; }}};

for (var f of flat(arr)) {

console.log(f);

}

Thanks for reading!