The following code example is what i found here on the internet
arr[1].push('native', 'laravel');
with a description of
Here we use the javascript array push method to add two new elements(items) to the inner sub-array.
which was exactly what i wanted to accomplish!
But when i tried it several times by my self it always went like this:
let mainArr = [];
console.log("mainArr: ", mainArr);
// Working as expected: created an empty array
let emptyArr = [];
console.log("emptyArr: ", emptyArr);
// Working as expected: created an empty array
for (i = 0; i < 3; i++) {
mainArr.push(emptyArr);
}
console.log("mainArr: ", mainArr);
// Working as expected: pushed 3 times the "emptyArr" into "mainArr"
let newArr = [["X"], [90]];
mainArr[0].push(newArr);
console.log("mainArr[0]: ", mainArr[0]);
console.log("mainArr[1]: ", mainArr[1]);
console.log("mainArr[2]: ", mainArr[2]);
// NOT working as expected: pushed "newArr" into every of the three arrays within the "mainArr" !!!
// How can I solve this?
Would love to hear some tips :)
Thanks!