We will give a simple example of a 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']
];
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.
JavaScript Array Methods | javaScript Tutorial for Beginners
How to add arrays or elements(Items) in a multidimensional array. We will explain it.
arr[1].push('native', 'laravel');
Here we use the javascript array push method to add two new elements(items) to the inner sub-array.
How to 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.
How to convert string to float Number in Javascript
How to remove elements (Items) in a multidimensional array. We will explain it.
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.
How to Remove an 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.
☞ JavaScript Programming Tutorial Full Course for Beginners
☞ Learn JavaScript - Become a Zero to Hero
☞ Javascript Project Tutorial: Budget App
☞ E-Commerce JavaScript Tutorial - Shopping Cart from Scratch