Get Programming with JavaScript - Listing 8.08

Listing 8.08 - Calling forEach with an inline function

var items = [ "The Pyramids", "The Grand Canyon", "Bondi Beach" ]; console.log("Dream destinations:"); items.forEach(function (item) { console.log(" – " + item); });

Further Adventures

Listing 8.08 - Calling forEach with an inline function - Task 1

var items = [ "The Pyramids", "The Grand Canyon", "Bondi Beach" ]; console.log("There are " + items.length + " dream destinations:"); items.forEach(function (item) { console.log(" – " + item); });

Listing 8.08 - Calling forEach with an inline function - Task 2

var items = [ "The Pyramids", "The Grand Canyon", "Bondi Beach" ]; var showItems = function () { console.log("There are " + items.length + " dream destinations:"); items.forEach(function (item) { console.log(" – " + item); }); };