Js array recursive loop

cyclic array

arr = [
   [1, 2],
   [3, 4],
]

output [13,14,23,34] ;

cyclic array

arr = [
   [1, 2],
   [3, 4],
   [5, 6],
]

output [135136145146235236245246]

The length of the array of the

loop is unknown, and the length of each subarray of the array is unknown.

do you want to write a general method?

Mar.02,2021

use the array reduce method
let arr = [[1,2], [3,4], [5,6]]
let list = []
arr.reduce ((pre, current, index, arr) = > {

list = []
for (let i = 0; i < pre.length; iPP) {
    for (let j = 0; j < current.length; jPP) {
        list.push(+(pre[i] + '' + current[j]))
    }
}
return list

})

console.log (list)

Menu