Array.map calls a callback for each array item and returns a new array containing the callback’s return values. It avoids manually creating an output array and pushing transformed items into it. section 9.1.4
Extracting weapons
Transform ninja objects into an array of weapons: `const weapons = ninjas.map(ninja => ninja.weapon);` section 9.1.4
Listing 9.7. Mapping an array
const ninjas = [
{name: "Yagyu", weapon: "shuriken"},
{name: "Yoshi", weapon: "katana"},
{name: "Kuma", weapon: "wakizashi"}
];
const weapons = ninjas.map(ninja => ninja.weapon); #A
assert(weapons[0] === "shuriken"
&& weapons[1] === "katana"
&& weapons[2] === "wakizashi"
&& weapons.length == 3, "The new array contains all weapons");
See the mapping example and its checks that the new array contains each weapon. section 9.1.4







