Multidimensional Array In JavaScript
In JavaScript, there is no any built-in support for working with multidimensional array. However, you can work wit multidimensional array by defining an array inside another array. You can use the following syntax if you want to access any value inside such array: array_name[x][y]. In this post, we will see an example of displaying items in a two dimensional array. Its just an array of my favourite dishes โ๐. In order to display each element, we will use a nested for-loop. If you are working with a 3D array then you will need 3 for-loops to display the value and so on. In real life projects working with multidimensional array is not really applicable expecially when the size of array is very large. And we use objects to work with such scenarios.
<!DOCTYPE html>
<html>
<head>
<title>Multidimensional Array</title>
</head>
<script>
var dish = [
["Crunchy Chicken", "Chicken Lollipop", "Chicken Roast", "Chicken Drumstick"],
["Kadai Paneer", "Palak Paneer", "Paneer Tikka", "Paneer Makhani"],
["Potato Stick", "Aloo Chop", "Aloo Dum", "Potato Chips"]
]
document.write("Dishes: " + "
");
for (var i=0; i<4; i++)
{
for (var j=0; j<4; j++)
{
document.write("[" + i + "]" + " " + "[" + j + "]" + "=" + dish[i][j] + "
");
}
document.write("
");
}
</script>
<body>
</body>
</html>
If you run the above code in your browser then you can see the name of dish along with the 2D-array index.
Leave Multidimensional Array In JavaScript to:
Read more #hive-163521 posts
Best Posts From Leo Umesh
We have not curated any of leoumesh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Leo Umesh
- The Tattoo of My Newborn Baby Girl Forever Inked on My Skin
- Long Weekend Food Feast With Wife
- String Manipulation in C#: Part 2
- String Manipulation in C#
- Introduction to C# and .NET
- Weekend Escape To Falls
- Evening Barbecue With Favourite Beer ๐บ ๐ป
- NumPy Broadcasting
- Summer BBQ
- Review of "The Day of The Jackal" Series
- Wonders of Wave Rock, Western Australia
- Trying To Make Authentic Chicken Dum Biryani At Home
- Beautiful Ocean Lookout in South West Australia
- Esperance: Hidden Paradise of Western Australia
- Cruising Through Blue Haven Beach
- My First Tattoo
- Exploring Flavoursome Veggie Indian Cuisines
- Australia's Popular Drink: Homemade
- An Everlasting Flowers
- Unexpected Rainbow At Wellington Dam, Western Australia