After researching various topics related to the issue, I found that the solutions provided are not working for me. It seems like there is a logic problem in my code. It's quite simple - I have two arrays (one containing three strings and the other containing three dates).
My goal is to create an object that pairs the first string from the first array with the first date from the second array.
The issue I'm facing is that the function theMainFunc() is creating three objects with the last index of each array, instead of matching them as intended.
Below is the code snippet:
var dlcNameList = ['they shall not pass', 'in the name of the tsar', 'apocalypse'];
var dlcReleaseDate = [new Date(2017,2,28), new Date(2017,6,15), new Date(2017,11,25)];
function objectCreator (dlcObject,dlcName,dlcDate) {
dlcObject.name = dlcName;
dlcObject.date = dlcDate;
return dlcObject;
}
function theMainFunc() {
var dlcDetails = {};
var i = 0;
var storage = [];
var x;
for (i; i <= 2; i++){
x = objectCreator(dlcDetails,dlcNameList[i],dlcReleaseDate[i]);
storage[i] = x;
}
return storage; //This returns an array with three "Same" objects. Not what I want to really acheive
}
console.log(theMainFunc())