Làm phẳng mảng dùng phương pháp đệ quy

flat_array,tipjs

Làm phẳng mảng dùng phương pháp đệ quy

let result = []
let flatten = function (arr) {
  for (let i = 0; i < arr.length; i++) {
    let item = arr[i]
    if (Array.isArray(arr[i])) {
      flatten(item)
    } else {
      result.push(item)
    }
  }
  return result
}
let arr = [1, 2, [3, 4], [5, [6, 7]]]
console.log(flatten(arr));// [1,2,3,4,5,6,7]

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

Detect when your site is visible to users

Detect when your site is visible to users

Promise + gì

promise + gì

Remove item in array javascript es6

Những bạn nào mà đã sử dụng ES6 một thời gian rồi thì có thể sử dụng method array.filter()

using javascript callback style error handling

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 .