There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
There will be two or more lengths that we can discern from the nested array. The outer array will have a length, namely the number of elements. The inner arrays will have their own lengths, independent of the outer list.
const numberClusters = [[1,2], [3,4], [5,6]]; //index 0 is [1,2], index 1 is [3,4], index 2 is [5,6]
const targetIndexOne = numberClusters[1]; //this references index 1 which is an array within an array. Index 1 is [3,4]
const targetIndexZero = numberClusters[0]; // This references index 0 which is [1,2]. Index 0 of this array is 1. Index 1 of this array is 2
const target2 = numberCluster[0][1] ; // This will target the number 2
When I write the target variable, I am confused on why I have to add the const target = numberClusters[2][1];. What do the two numbers at the end mean?
Take it one step at a time. What is numberClusters? Well, it’s an array! To access elements in an array, we can use bracket notation wrapping the element index. So when we write numberClusters[2] we are accessing the 3rd element in the numberClusters array. Now, this element is an array itself and we want to access the second element in this nested array, so we write numberClusters[2][1] which will first access the 3rd element in the array (which is itself an array), then access the 2nd element in this nested array
That’s actually a very good question (anyone who has a better answer than the one I’m about to give please jump in LOL)!
Firstly, just an fyi, I’m not too familiar with Arrayception… expect that it’s a model problem that may or may not be related to associated arrays. (Feel free to elaborate on this haha ) But back to the point, I always find naming an interesting concept. I’ve had similar questions only too often, but have been walking in circles for a direct answer. I guess sometimes the key is knowing that something works… I suppose “nested array” is an appropriate name though, because if the variable stores an array, that can be analogous to a container. Then imagine that inside the first container are two more containers that fit. And per the word’s definition, “nest” (as a verb) means “to fit,” so it’s like arrays are being fitted, or nested, inside broader arrays.
Ahh I realize this might be a lot to read at once, but I hope it helped!
Yes, you can! I tried using .reverse() on an exercise of mine! Please check my example below:
// This is a nested array done by myself, where there are 3 nested arrays that have nested arrays within
const nestedArr3 = [[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[11, 12, 13], [14, 15, 16], [17, 18, 19]], [[21, 22, 23], [24, 25, 26], [27, 28, 29]]];