So, this loop keeps repeating the output even when I tried to set the length as a variable and changing it in the inner loop.
Here's my code:
let testData = {
'title': ['Dark knight', 'Monty python the holy grail', 'the social network'],
'description': ['Batman yelling', 'Random stuff', 'facebook stuff']
};
generateFile(testData);
function generateFile(testData){
for (let i =0; i < testData.title.length; i++){
title = testData.title[i]
for (let j = 0; j < testData.description.length; j++){
description = testData.description[j];
console.log(title);
console.log(description);
}
}
}
and this is the output:
Dark knight
Batman yelling
Dark knight
Random stuff
Dark knight
facebook stuff
Monty python the holy grail
Batman yelling
Monty python the holy grail
Random stuff
Monty python the holy grail
facebook stuff
the social network
Batman yelling
the social network
Random stuff
the social network
facebook stuff
and it's supposed to output only one time.