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

Lấy tháng hiện tại trong javascript

Lấy tháng hiện tại trong javascript

Remove array of objects from another array of objects

Remove array of objects from another array of objects

Merge Array

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

Getting the last element of a split string array

Getting the last element of a split string array

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs