flatMap()

array,tipjs

Use flatMap() creates a new array with sub-array elements flattened by specified depth.

[[2], [4], [6], [8]].flatMap(val => val/2) // [ 1, 2, 3, 4 ]

var new_array = arr.flatMap(function callback(currentValue[, index[, array]]) {
 // return element for new_array
}[, thisArg])

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

Tránh viết biến có phạm vi global

Đôi khi bạn cần phải viết một tập lệnh trực tiếp trên trang. Cần lưu ý rằng trong code của bạn vô tình khai báo một biến toàn cầu. Vì phạm vi toàn cầu phức tạp hơn nên việc tìm kiếm chậm hơn rất nhiều

How to reverse an Array?

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

serialize Form

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

Spread Operator for Objects

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

Extend Object javascript

Extend Object javascript