How to push an array to a Multidimensional Array in JavaScript?

02-Jun-2023

.

Admin

How to push an array to a Multidimensional Array in JavaScript?

Now, let's see article of javascript: multidimensional array with push pop. if you want to see example of javascript push multidimensional array then you are a right place. we will help you to give example of javascript: multidimensional array with push pop. This tutorial will give you simple example of learn javascript multidimensional array by examples.

To push an array to a multidimensional array in JavaScript, you can use the push() method. Here's an example:

Example 1:


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>How to push an array to a Multidimensional Array in JavaScript? - NiceSnippets.Com</title>

</head>

<body>

</body>

<script type="text/javascript">

let multiArray = [[1, 2], [3, 4]];

let newArray = [5, 6];

multiArray.push(newArray);

console.log(multiArray); // Output: [[1, 2], [3, 4], [5, 6]]

</script>

</html>

In this example, we have a multidimensional array called `multiArray` that contains two arrays. We also have a new array called `newArray`. To push `newArray` to `multiArray`, we simply call the push() method on `multiArray` and pass in `newArray` as an argument.

After pushing the new array to the multidimensional array, we log the updated value of `multiArray` to the console. The output shows that the new array has been successfully added as a third element in the multidimensional array.

#JavaScript