JavaScript: Multidimensional Array With Push Pop

JavaScript: Multidimensional Array With Push Pop

In this js array tutorial, you will learn about JavaScript multidimensional array. And also learn how to access javascript multidimensional array, How to add elements in a multidimensional array, Remove items in multidimensional array & looping with multidimensional. We will give a simple example of a JavaScript multidimensional array.

Multidimensional Array In JavaScript

  • 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 composed of two or more arrays. In other words, An array whose elements consist of arrays. We will explain with the following multi-dimensional array.

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

Access Items Of Multidimensional Array

How to access items of a multidimensional array. Let’s we will explain. Use the Square brackets of access to array items as following below example.

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

How to add arrays or elements(Items) in a multidimensional array. We will explain it.

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'] );

We display using the javaScript push method to add a new array to the outer array.

Remove Items in Multidimensional Arrays

How to remove elements (Items) in a multidimensional array. We will explain it.

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

Here we use the javascript array pop method to remove elements(items) to the inner sub-array. It will remove the last element(item) of an array.

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

We display using the javaScript pop method to remove the array to outer array. This removes the last array of outer array.

You may like

  1. JavaScript Array splice() Method By Example
  2. Sorting Using JavaScript Array Sort() Method
  3. JavaScript: Clone an Array & Object By Examples
  4. JavaScript: Convert String to Array JavaScript
  5. Remove First, last and specific Element From Array Javascript
  6. javaScript Push() Array By Example
  7. javaScript Push Array, Items Into Array Example
  8. JavaScript Check the Object | isArray() Function

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *