in ,

Javascript Notes – Mixing Arrays and Objects

Here are several examples of mixing Arrays and Objects together.

 

And here is version 4, which I did later, and I actually think this is the best:

// the array that we are working with
var movieData = [
  {
    Title: "12 Angry Men",
    Rating: 5,
    hasWatched: true
  },
  {
    Title: "Metropolis",
    Rating: 2,
    hasWatched: false
  },
  {
    Title: "The 3rd Man",
    Rating: 3,
    hasWatched: false
  }
];


//creating a function that loops over the array and prints a string for each item in the array
function printMovieData() {
  movieData.forEach(function(movie) {
    if (movie.hasWatched === true) {
      var watchStatus = " have seen ";
    } else {
      var watchStatus = " have not seen ";
    }
    console.log(
      "You" + watchStatus + movie.Title + " - " + movie.Rating + " stars"
    );
  });
}

Javascript Notes – Objects

Javascript Notes – Adding Methods to Objects