One fully expected that this would be pure gibberish, so don’t feel as we’re expecting you to be grateful, or understand it. We simply sprang it upon you as a sneak peak to what you will be able to “arrive there” on your own, in due course of time. That is the goal. No pressure.
The subject of your lessons at present is, loops. I won’t characterize them in my own view except to say they are the mustard that goes with the frank in a hot dog. Take them out of the picture and programming is no longer possible. That is how important this concept is to programming in any language, even machine language. It’s all centered around loops.
Loops involve iteration and in your studies you will learn about ‘iterators’, of which .map()
above is one. It’s essentially a self managing loop. That is how we could iterate over all the items in the input array.
The subject of Object
should come up at some point, even if it is happensatance to your extra reading. It bears extra study. Plain objects do not inherit a, keys()
, values()
, or, items()
method from their parent class’s prototype. We must go to the parent class itself to access those methods. Object
is the parent class of all objects in JS. Hence,
Object.values(object)
Of course the return from that is an array, and all we want is the actual value,
Object.values(x)[0]
being the only, therefore first value in that array. This is a matter for extra study that while not important now, will be by the time you reach the end of this course. Definitely add it to your post-course reading/study/practice todo list.
In the course of your learning to apply Array methods, you will encounter the, Array.join(separator_string)
method. It is the way we convert an array to a string object. Give that extra study when you learn the, String.split()
method. They are inverse functions that work hand in hand through a lot of string manipulation logic. While easy to learn, it is difficult to apply. Practice will show us that, and will enable us to circumvent or mitigate special cases.
We used some rather off the cuff logic in the example that no doubt would raise a few eyebrows among unseasoned readers, namely new learners who have not yet been exposed to logical operations. If nothing else stumped you, that return line would surely have. It is tied to the return value of the method above it, something that will also need learning about and practice.
The only intention on my part was to expose you to what you will someday soon be doing on your own. It is not something we conceived of, out of the blue. It only came about in this fashion because of what we understand of what the language promises. That is why reading and practice are so important. To know a language means knowing all of its promises, over and above the syntax and usage aspects. Of course we don’t learn this stuff over night. In lessons and practice we begin to see with our own eyes and think with our own brain. By that and promises made by the language we see the range of possibilities that can be applied to solving any problem.
Stay the course in your lesson plan. Don’t try to supersede the object of the lesson; if anything, try to mete out as much information and clarity as you can before moving on to the next one. Let your brain soak this up, and keep your expectations low. It helps with the surprise when you reach the ‘eureka moment’.
Happy coding!