March 12th, 2020
Before we begin, I’d like to make sure you’ve checked out yesterday’s story. If you have, well done! Today we’ll be talking about multidimensional arrays! If you haven’t, feel free to check out yesterday's topic on the link below!
Javascript in 15 Days : Arrays
So, this is a continuation of yesterday's topic, arrays. As you've noticed, when we discussed about loops, we discussed about nested loops, or loop inside a loop, and now, the same concept will be applied to arrays. Array, as discussed, can hold any data type, which can also mean, it can hold arrays, which are called multidimensional arrays, or if it makes you easier, array in arrays. Now, let's talk about how a multidimensional array looks.
Now, as you can see above, we declared a variable students with its structure being a multidimensional array, and when we run the script, the console.log
on line 6
will print the correct output, which can be seen above (on line 8 ~ 12
).
Now that you know the structure, let's move up the ladder. As you've noticed, since multidimensional arrays are by default, of type array, all methods and properties on an array can also be used in multidimensional arrays. Now, let's try manipulating the students variable. FYI, the inner array, by default consists of 3 values, with the correct order of name, age, gender.
Now that we're done covering the basic methods of manipulating a whole array, let's see what happens if we want to manipulate the inner array, or the element itself.
So, as you can see, it's exactly like yesterday, but a little more advanced. Look, if you don't really get it, that's fine, you'll slowly get the hang of it with a lot of practice. I got a challlenge for you, try to use the splice and slice on the multidimensinal array, and hit me up if you're done or stuck on Twitter or LinkedIn. Have a great day!