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

Remove array of objects from another array of objects

Remove array of objects from another array of objects

Kiểm tra định dạng email bằng Javascript

Kiểm tra định dạng email bằng Javascript

So sánh hai array trong javascript

Làm thế nào để đánh giá xem hai mảng có bằng nhau không? Có hai cách đó là sử dụng JSON.stringify() hoặc toString()

Đếm có bao nhiêu items giống nhau trong một array

reduce javascript. Đếm có bao nhiêu items giống nhau trong một array

Hàm lày ngày trong tuần javascript

Hàm lày ngày trong tuần javascript