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

Spread Operator for Objects

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

Convert Array-like to True Array

Convert Array-like to True Array

encode/decode base64 with JS

Encoding to base64 is done with the btoa command

Getting the last element of a split string array

Getting the last element of a split string array

Đế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