How to push with a multidimensional array with JavaScript?

Estimated read time 1 min read

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]];
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.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply