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

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.

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs

serialize Form

Sử dụng formdata constructor để convert form, FormData, array.from(). Kết hợp window.encodeURIComponent() để encode từng value trong form.

Random String

Random String với độ dài tuỳ chọn

group by property javascript use reduce

group by property javascript use reduce