I have a JS program that generates an index a random number of times. The indexes are correlated to strings stored in another array. It then pushes those indexes into yet another array. When I console log the randomly generated indexes, it returns the strings associated with those indexes. However, when I log the array that holds the generated strings, it always skips the first generated string. How can I get the second array to log all of the generated strings without skipping the first one? (Note that getRandStrings is defined prior to this in the code.)
let stringsBlockArr = [];
let getStrings = () => {
stringsBlock = [];
let stringsBlock = [];
let numStringsPerTurn = (Math.floor(Math.random() * 3));
for (let i = 0; i < numStringsPerTurn; i++) {
stringsBlock += getRandStrings();
}
stringsBlockArr.push(stringBlock);
}
getStringsPerTurn();
console.log(stringsBlockArr);
For example, if the generated strings are “a”, “b”, and “c”, logging stringsBlockArr only returns “b” and “c”.
I have tried only defining the getStringsArr locally. It didn’t work and I need that array to be available globally.