Arrays
7 min · JavaScript
Hold many values under one name, and reach for the one you want.
JavaScript · Arrays0/5 cleared
Enemy 1 of 5
Every variable so far has held one value at a time. An array changes that: it holds several values in order, all under one name, inside square brackets [ ] separated by commas — a single labeled list of slots instead of one box.
Arrays are everywhere in real JavaScript code because so much real-world data is naturally "a bunch of things": a list of scores, a set of usernames, the items in a shopping cart. Instead of creating fruit1, fruit2, fruit3 as separate variables, you group them into one array and can loop over, search, or grow the whole collection at once.
You
Kernel Hellhound
Loading editor...
Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: [ 'apple', 'banana', 'cherry' ]