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

Random Number javascript

Random Number javascript

Using promises to catch errors

Remove array of objects from another array of objects

Remove array of objects from another array of objects

encode/decode base64 with JS

Encoding to base64 is done with the btoa command

using async/await to catch errors