Implement Two Dimensional Arrays In JavaScript Part III of Array Series
An array specifies a variable that can be indexed as a list in rows and columns. A two-dimensional array is an array of arrays requiring two indices to select an element.
The first index is zero as is common in most programming languages. JavaScript objects can be used as associative arrays.
An array is a data structure consisting of a collection of elements which are values or variables.
Common Functions For Manipulating Two Dimensional Arrays In JavaScript
Common Array Functions
Name | Description | Example |
---|---|---|
Array.push() | Append row | int_array.push([4, 5, 6]); |
Array.splice() | Add row at specified index | int_array.splice(1, 0, [7, 8, 9]); |
Array.splice() | Remove row at specified index | int_array.splice(1, 1); |
Array.unshift() | Insert row at the beginning | int_array.unshift([0, 0, 0]); |
Name | Description | Example |
JavaScript Two Dimensional Arrays Snippet
// OjamboShop.com Learning JavaScript Arrays Part III Tutorial // let int_array = [ [11,22,33], [111,222,333]]; let array2D = [["Ford","F-Series",1984],["GMC","C-Series",1986]]; console.log(int_array); console.log(array2D); int_array.push([4, 5, 6]); // Append row console.log(int_array); int_array.splice(1, 0, [7, 8, 9]); // Add row at index console.log(int_array); int_array.unshift([0, 0, 0]); // Insert row at beginning console.log(int_array);
Usage
You can use any IDE or text editor and the web browser to compile and execute JavaScript code. For this tutorial, the OjamboShop.com Learning JavaScript Course Web IDE was used to input and compile JavaScript code for the two dimensional arrays.
Open Source
JavaScript follows the ECMAScript standard and is licensed under the W3C Software License by web browser vendors and runtime environment vendors. This allows commercial use, modification, distribution, and allows making derivatives proprietary.
Learn Programming Courses:
Courses are optimized for your web browser on any device.
Limited Time Offer:
OjamboShop.com is offering 20% off coupon code SCHOOL for Learning JavaScript Course or Learning Python Course or for Learning PHP Course until End Day 2024.
Learn Programming Ebooks:
Ebooks can be downloaded to your reader of choice.
Conclusion:
JavaScript makes it easy to use two dimensional arrays. Use two dimensional arrays to an array of arrays requiring two indices to select an element.
Take this opportunity to learn the JavaScript, Python or PHP programming language by making a one-time purchase at Learning JavaScript Course or Learning Python Course or Learning PHP Course. A web browser is the only thing needed to learn JavaScript, JavaScript or PHP in 2024 at your leisure. All the developer tools are provided right in your web browser.
If you prefer to download ebook versions for your reader then you may purchase at Learning JavaScript Ebook or Learning Python Ebook or Learning PHP Ebook
For custom websites, app development and one-on-one tutorials, go to OjamboServices.com.
References:
- JavaScript Arrays Article Part I
- JavaScript Arrays Article Part II
- Learning JavaScript Course on OjamboShop.com
- Learning Python Course on OjamboShop.com
- Learning PHP Course on OjamboShop.com
- Learning JavaScript Ebook on Amazon
- Learning Python Ebook on Amazon
- Learning PHP Ebook on Amazon
- OjamboServices.com For Custom Websites, Applications & Tutorials