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

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs

Đếm số phần tử trong mảng JavaScript

Đếm số lần xuất hiện của các phần tử trong mảng JavaScript

Async await in javascript

Async await in javascript

promise in javascript

promise in javascript

Copy a string to the clipboard

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).