To push an element to a multidimensional array in JavaScript, you can use the Array.push()
method on the outer array to add a new inner array containing the element.
Here’s an example:
let array = [[1, 2], [3, 4]];
array.push([5]);
console.log(array); // [[1, 2], [3, 4], [5]]
In this example, we create a multidimensional array array
with two inner arrays. To add a new element to the outer array, we use the Array.push()
method to add a new inner array containing the element 5
. The resulting array is then logged to the console.
+ There are no comments
Add yours