I checked alot of topics around here considering the subject but the solutions do not seem to work for me. I guess I have some logic problem. My code is very simple. I have two arrays (The first contains three strings and the second contains three dates)
All I want to do is to store the first string in the first array with the first date in the second array in an object.
The problem with the code that the array I create in the function theMainFunc() is saving 3 objects with the last index of each array instead of matching them like I need.
Here is the code:
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())