How to use the spread operator to flatten array of objects in javascript

es6,spread_operator_javascript

How to use the spread operator to flatten array of objects in javascript

function flatten(arr) {
  while (arr.some((item) => Array.isArray(item))) {
    arr = [].concat(...arr)
  }
  return arr
}
let arr = [1, 2, [3, 4], [5, [6, 7]]]
console.log(flatten(arr))

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

Rolling loading

Nguyên tắc là theo dõi các sự kiện cuộn trang và phân tích mối quan hệ thuộc tính giữa clientHeight , scrollTop và scrollHeight .

Getting the last element of a split string array

Getting the last element of a split string array

Await in a for loop

How to Await in a for loop

group by property javascript use reduce

group by property javascript use reduce

serialize Form

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