I’m receiving an error …push() is not a function. I believe it’s because I didn’t declare the array properly. This might seem like a mess
window.count=0; // declare global variable
let questionsArray = [0]; // declare array
window.count++ // now the var value is 1
questionsArray.push(['window.count']); // push the variable as a single value array
questionsArray[window.count].push(false) // push a boolean into the nested array,
line 5 returns an error
the console.log shows the array contains a single value of 0, as it was declared with, and nothing was pushed, as in I didn’t write the correct code to push a single value array.
Maybe I am wrong with interpreting the error. I would appreciate some help on how to get an array looking like this:
will push an array containing the string ‘window.count’
that is your problem, I don’t know what you are trying to do but
questionsArray.push([window.count]) may be what you want.
that way when you do questionsArray[1] it references an array
your issue is that this is not an array questionsArray is an array, but it doesn’t have subarrays, so you can’t push to any subarray of questionsArray - you can push only to an already existing array
I understand, so pushing a single value array is impossible?
A line like this, I suspect was ignored in that case questionsArray.push(['window.count']);
Could you suggest a different approach how to build up nested arrays with a variable after an increment ?