0
Challenge · 07Just Enough JavaScript

Arrays: your main container

JavaScriptused in ~100% of apps

Almost every problem you will be given hands you a list of things and asks a question about it. This is that list. If you only ever truly learn one container, make it this one.

Core idea. An array is a numbered row of boxes. The numbering starts at 0, not 1, and every problem you meet will use that fact. You reach into any box instantly if you know its number.
Playground, this isn't a screenshot
const names = ["asha", "ravi", "meera", "dev"]
asha
0
ravi
1
meera
2
dev
3
names[1]       // "ravi"
names.length   // 4
names[0]       // "asha"  (the FIRST one)
names[4]       // undefined
// 4 boxes, but the last number is 3.
// The last one is ALWAYS length - 1.

Four boxes, numbered 0 to 3. Reaching past the end gives you undefined rather than an error, which is why the mistake hides.

↑ play a little first, then dig in