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

promise in javascript

promise in javascript

Rest Operator for Objects

Now we can use rest on the properties of an Object. It allows us to explicitly extract certain named variables, and assign any uncalled variables into a catchall Object.

Sự khác biệt giữa substr và substring

Sự khác biệt giữa substr() và substring() chức năng trong JS là gì?

JavaScript: async/await with forEach

JavaScript: async/await with forEach()

Detect when your site is visible to users

Detect when your site is visible to users