Formation Prestashop intégrateur: ES6 / Gestion de plusieurs valeurs en retour de fonction

Vous êtes ici : Accueil / Prestashop intégrateur / ES6 / Gestion de plusieurs valeurs en retour de fonction

Gestion de plusieurs valeurs en retour de fonction

Vous pouvez utiliser un tableau pour stocker plusieurs valeurs.

Vous pouvez ignorer certaines valeurs retournées.

function function_name()
{
    //here we are storing variables in an array and returning the array
    return [1, 6, 7, 4, 8, 0];
}

var q, w, e, r, t, y;

// Here we are using ES6's array destructuring feature to assign the returned values to variables.
// Here we are ignoring 2 and 4 array indexes
[q, w, , r, , y] = function_name();

// y is 0
alert(y);