⊗jsPmRcSM 279 of 504 menu

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.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline