JavaScript Multidimensional Array Push Pop

JavaScript multi dimensional array; Through this tutorial, i am going to show you what is JavaScript multidimensional array and how to use multidimensional array with push pop elements from array.

JavaScript Multidimensional Array with Push Pop

  • JavaScript Multidimensional Array
  • Access Items Of Multidimensional Array
  • Add Items in Multidimensional Array
  • Remove Items in Multidimensional Array

JavaScript Multidimensional Array

A JavaScript multidimensional array is define of two or more arrays of arrays. In other words, An array whose elements consist of arrays.

See the following example of multi-dimensional array in javaScript; as shown below:

var arr = [
     ['php', 'python', 'perl'],
     ['xampp', 'mysql', 'sql'],
     ['jquery', 'javaScript', 'angular', 'react']
 ];

Access Items Of Multidimensional Array

Here, i will create an example for access items from multidimensional array; as shown below:

document.write(arr[1][1]);
// output
// mysql

The JavaScript array index starts with zero. The first bracket refers to the desired item in the outer array. The second bracket refers to the desired item in the internal array.

Add Items in Multidimensional Arrays

Here, i will take next example for add arrays or elements(Items) in a multidimensional array; as shown below:

Add Elements(Items) of an array :
arr[1].push('native', 'laravel');

Here we use the javascript array push method to add two new elements(items) to the inner sub-array.

Add a new array of multidimensional array :
arr.push( ['testing', 'rust', 'c'] );

Remove Items in Multidimensional Arrays

Here, i will take third example for remove elements (Items) in a multidimensional array; as shown below:

Remove Elements(Items) of an array :
arr[0].pop();

It will remove the last element(item) of an array.

Remove array of multidimensional array :
arr.pop();

More JavaScript Tutorials

Leave a Comment