'Javascript nested array to integer
I have a nested array
const folder = [1, [2, [3, [4, [5, [6]]]]]];
please use the basic concept of javaScript. I need return like 123456. what should I do? i tried using for loops but it didn't work.
Solution 1:[1]
use the recursive function here. find the below solution
const folder = [1, [2, [3, [4, [5, [6]]]]]];
let result = '';
function convert(arr) {
arr.forEach((val) => {
if (Array.isArray(val)) {
convert(val);
} else {
result = result + val
}
})
return result
}
console.log(convert(folder))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ali Demirci |
