Manipulations with elements in JavaScript
Let's do something with the iterated elements
of the array, for example, write the sign
'!' at the end of them.
In this case, we'll have to use the ordinary
for loop instead of for-of,
like this:
function func(arr) {
for (let i = 0; i < arr.length; i++) {
if (typeof arr[i] == 'object') {
arr[i] = func(arr[i]);
} else {
arr[i] = arr[i] + '!';
}
}
return arr;
}
console.log(func([1, [2, 7, 8], [3, 4, [5, 6]]]));
Given a multidimensional array of arbitrary nesting level, for example, this:
[1, [2, 7, 8], [3, 4], [5, [6, 7]]]
Square all elements-numbers of this array.