Map en noms
importance: 5
Vous avez un tableau d’objets user
, chacun ayant user.name
. Écrivez le code qui le convertit en un tableau de noms.
Par exemple :
let john = { name: "John", age: 25 };
let pete = { name: "Pete", age: 30 };
let mary = { name: "Mary", age: 28 };
let users = [ john, petemary ];
let names = /* ... votre code */
alert( names ); // John, Pete, Mary
let john = { name: "John", age: 25 };
let pete = { name: "Pete", age: 30 };
let mary = { name: "Mary", age: 28 };
let users = [ john, pete, mary ];
let names = users.map(item => item.name);
alert( names ); // John, Pete, Mary