I'm starting with two equal-length arrays, and I'd like to create a new array made up of sub arrays, each of which are made from combining elements at each index of both arrays. Here is what I mean:
// the 2 initial arrays:
var arr1 = ["Quote1", "Quote2", "Quote3"];
var arr2 = ["Author1", "Author2", "Author3"];
// the output I need to achieve:
[ ["Quote1", "Author1"], ["Quote2", "Author2"], ["Quote3", "Author3"] ];
The problem is that my code produces the following output to the console.log:
Array [ Array[2], Array[2], Array[2] ]
The problematic output I'm getting doesn't show the actual values of each subarray, it only shows the length of each subarray.
Here is my code:
var quotesArr = ["Quote 1", "Quote 2", "Quote 3"];
var authorsArr = ["Author 1", "Author 2", "Author 3"];
var quoteMeetsAuthor = [];
var quotesAndAuthors = [];
function combineArrays(quotes,authors) {
if (quotes.length != authors.length) {
console.log("Danger Will Robinson!");
retu "Danger Will Robinson!";
}
for (i=0; i<quotes.length; i++) {
quoteMeetsAuthor.push(quotes[i]);
quoteMeetsAuthor.push(authors[i]);
quotesAndAuthors.push(quoteMeetsAuthor);
quoteMeetsAuthor = [];
}
console.log(quotesAndAuthors);
retu quotesAndAuthors;
}
combineArrays(quotesArr, authorsArr);
Can anyone offer advice?
