Well David, you can use the map function as well as Nina did, or you can just use the typical for loop way:
var scratchData = [
{name: 'Billy Boy', grade: 'D'},
{name: 'Serious Sara', grade: 'B'},
{name: 'Tepid Tom', grade: 'C'} ];
var get = ' is getting an '; // declaring it with var so it's easier to use
function makeStudentsReport(data) { // data will be the array
for (var i = 0; i < data.length; i++){
var everyObject = data[i]; // everyObject is every object in the array
console.log(everyObject.name + get + everyObject.grade);
}
}
makeStudentsReport(scratchData); // passing the array as a parameter to the function
Or more simple you can use Array.forEach() method:
function makeStudentsReport(data) {
data.forEach(function(object){
console.log(object.name + get + object.grade);
});
}
makeStudentsReport(scratchData);
for (var i=0;i<scratchData.length;i++) { console.log(scratchData[i].name+' is getting a(n) '+ scratchData[i].grade); }