Skip to content

Commit 02229ac

Browse files
committed
function added and checked
1 parent 3cd34e2 commit 02229ac

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function printElements(arr) {
2+
for (let i = 0; i < arr.length; i++) {
3+
if (Array.isArray(arr[i])) {
4+
// Recursive case: if the element is an array, go deeper
5+
printElements(arr[i]);
6+
} else {
7+
// Base case: if the element is not an array, print it
8+
console.log(arr[i]);
9+
}
10+
}
11+
}
12+
const multiDimensionalArray = [
13+
[1, 2, [3, 4]],
14+
[5, 6],
15+
[[7, 8], 9]
16+
];
17+
18+
printElements(multiDimensionalArray);

0 commit comments

Comments
 (0)