Using Objects with Arrays

Objects with Arrays

  • Since objects are used to represent real world “things”, they are often combined with arrays to represent a collection of real world things
// declaring an array that contains objects as items

let shows = [
  { name: "Breaking Bad", genre: "Drama", network: "AMC" },
  { name: "Game of Thrones", genre: "Fantasy", network: "HBO" },
  { name: "Silicon Valley", genre: "Comedy", network: "HBO" },
  { name: "Narcos", genre: "Drama", network: "Netflix" },
  { name: "Vikings", genre: "Action", network: "History Channel" },
  { name: "Power", genre: "Drama", network: "Starz" },
];


  • In the code example above, we have an array called shows that contains a collection of objects that represents some TV shows

Looping (iteration) through an array of objects

  • Looping through an array of objects is technically the same as looping through an array of any other datatype (i.e. strings, numbers, etc)

JS Bin on jsbin.com

This example uses html tables. Documentation for tables can be found here