Filter Unique Values

array,tipjs,es6

Kiểu đối tượng Set đã được giới thiệu trong ES6 và cùng với ..., ‘spread’ operator, chúng ta có thể sử dụng nó để tạo một mảng mới chỉ với các giá trị duy nhất.

const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // Result: [1, 2, 3, 5]

Nếu như trước đó các bạn chưa học ES6 thì những xử lý như thế này thường nhiều dòng mã hơn.

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

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

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

Rest Operator for Objects

Now we can use rest on the properties of an Object. It allows us to explicitly extract certain named variables, and assign any uncalled variables into a catchall Object.

How to reverse an Array?

Reversing an array in JS is really simple with the standard array method. Like below

Calculate the number of difference days between two dates

Calculate the number of difference days between two dates

closure javascript

closure javascript