Array.map






'il map()metodo crea un nuovo array eseguendo una funzione su ogni elemento dell'array.

'Il map()metodo non esegue la funzione per gli elementi dell'array senza valori.

'Il map()metodo non cambia la matrice originale.

'Questo esempio moltiplica ogni valore dell'array per 2:

'Esempio

'var numbers1 = [45, 4, 9, 16, 25];

'var numbers2 = numbers1.map(myFunction);

'function myFunction(value, index, array) {

' return value * 2;

'}


https://www.w3schools.com/js/tryit.asp?filename=tryjs_array_map

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.map()</h2>

<p>Creates a new array by performing a function on each array element.</p>

<p id="demo"></p>

<script>
var numbers1 = [45, 4, 9, 16, 25];
var numbers2 = numbers1.map(myFunction);

document.getElementById("demo").innerHTML = numbers2;

function myFunction(value, index, array) {
return value * 2;
}
</script>

</body>
</html>


'Si noti che la funzione accetta 3 argomenti:

'Il valore dell'oggetto

'L'indice dell'oggetto

'La matrice stessa

'Quando una funzione di callback utilizza solo il parametro value, i parametri index e array possono essere omessi:

'Esempio

'var numbers1 = [45, 4, 9, 16, 25];

'var numbers2 = numbers1.map(myFunction);

'function myFunction(value) {

' return value * 2;

'}


https://www.w3schools.com/js/tryit.asp?filename=tryjs_array_map_2

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.map()</h2>

<p>Creates a new array by performing a function on each array element.</p>

<p id="demo"></p>

<script>
var numbers1 = [45, 4, 9, 16, 25];
var numbers2 = numbers1.map(myFunction);

document.getElementById("demo").innerHTML = numbers2;

function myFunction(value) {
return value * 2;
}
</script>

</body>
</html>










( arraymap.html )- by Paolo Puglisi - Modifica del 17/12/2023