In this lesson, you kept Tomás’s lineup of films up to date as it changed at both ends, and asked it whether a film was there and where.
Key Points
- For every array method, ask two questions: what does it do to the array, and what does the call hand back, its return value?
push()adds an item at the end, andunshift()adds one at the start. Both change the array and hand back its new length, not the array.pop()removes the last item, andshift()removes the first. Both change the array and hand back the item they removed. Aftershift(), every other item moves up one index.constkeepslineupon the same array, but the array itself can still change.includes()hands backtrueorfalse.indexOf()hands back the index of the first match, or-1when the item isn’t there, the same not-found answer thatindexOf()gives on a string.at(0)hands back the first item, andat(-1)counts from the end and hands back the last.join()glues every item into one string, with whatever you pass it between them.join(", ")puts a comma and a space between the titles.- The methods in this lesson come in two kinds: the end methods change the array, and
includes(),indexOf(),at()andjoin()leave it alone and only hand back an answer. Methods you’ll meet later answer the two questions differently, so keep asking them. - A question you’ll ask again belongs in a function whose name asks it and that returns the answer, such as
isLinedUp().
Final Code
Here’s the whole session in Node’s REPL, from the first lineup to the last check: