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

try/catch es10

An update for developer convience allows the use of try/catch without an explicit e Error reference in the catch call.

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

group by property javascript use reduce

group by property javascript use reduce

Object.keys và Object.getOwnPropertyNames

Object.keys và Object.getOwnPropertyNames

Await in a for loop

How to Await in a for loop