What is the best way to efficiently populate an array with numerous objects created using a constructor?
I have a constructor function that creates TV and movie objects:
function Media(name, boxCover) {
this.name = name;
this.boxCover = boxCover;
};
I am creating many objects that I want to store in an array. My initial approach did not work as expected:
var table = [
var avengers = new Media("avengers",'../assets/boxcovers/avengers.jpg');
var blade_runner = new Media("blade_runner",'../assets/boxcovers/blade_runner.jpg');
var brave = new Media("brave",'../assets/boxcovers/brave.jpg');
var catching_fire = new Media("catching_fire",'../assets/boxcovers/catching_fire.jpg');
var django = new Media("django",'../assets/boxcovers/django.jpg');
var finding_nemo = new Media("finding_nemo",'../assets/boxcovers/finding_nemo.jpg');
];
I also attempted to use table.push(
at the beginning of each line. Do I really need to list each object individually in the array like this, or is there a more efficient method to avoid duplication?
table = [avengers, blade_runner, etc.