How to push a single value array?

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:

questionsArray = [0,[1,false],]
questionsArray.push(['window.count']); 

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

Same error, it doesn’t matter to me if it’s a string or a number. I’ve written it without ‘’ first time around.

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

2 Likes

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 ?

ok, I missed the subarray
is that your whole code?
there may be something else that changes window.count

it’s longer than that, I’m going to go through it tomorrow. Meantime, the error looks like this
image

Nevermind, I just didn’t know how to write code properly. It’s working now
image