I have been working on creating an array of objects with nested arrays, but I am facing an issue where data seems to go missing in the final step:
const args_arr = [];
const options_arr = [];
let options = '';
let text = "";
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 5; j++) {
if (i === j) {
args_arr.push(true);
} else {
args_arr.push(false);
}
}
text += args_arr + "<br>";
options = {
op1: true,
op2: false,
args: ['visible']
};
text += JSON.stringify(options) + "<br>";
options.args.push(args_arr);
text += JSON.stringify(options) + "<br>";
options_arr.push(options);
args_arr.length = 0;
}
text += '<br>' + JSON.stringify(options_arr) + "<br>";
document.getElementById("demo").innerHTML = text;
<pre id="demo"></pre>
All my code appears to be running correctly, except at the last stage when adding options to options_arr, some arrays after 'visible' are disappearing.
This is the outcome I'm observing:
true,false,false,false,false
{"op1":true,"op2":false,"args":["visible"]}
{"op1":true,"op2":false,"args":["visible", [true,false,false,false,false]]}
...
Can you help me identify what might be causing this issue?