Merge Array

tipjs,array

How to combine two sorted arrays into one? We can do this easily with the spread operator.

a1 = [1, 2, 5, 6, 9];
a2 = [3, 4, 7, 8, 10];

res = [...a1, ...a2]; // [1, 2, 5, 6, 9, 3, 4, 7, 8, 10]

But if we want to combine and sort? Again, nothing complicated!

res = [...a1, ...a2].sort((a, b) => +a > +b); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Có thể bạn đã miss một số snippets code

closure javascript

closure javascript

Remove item in array javascript es6

Những bạn nào mà đã sử dụng ES6 một thời gian rồi thì có thể sử dụng method array.filter()

Callback in javascript

Callback in javascript

Spread Operator for Objects

Using the spread operator during an Object declaration will assign the properties of the referenced Object to the new Object.

10 mẹo sử dụng array và object trong javascript

10 mẹo sử dụng array và object trong javascript