Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 1 KB

README.md

File metadata and controls

37 lines (24 loc) · 1 KB

17. Arrays and indexing

Store ordered collections and access their elements.

Learn

  • array literals
  • index
  • length
  • push
  • pop

How it works

Arrays are objects with ordered, zero-based positions. length is one more than the highest populated index, not a count of meaningful values in a sparse array. Methods such as push and pop mutate; slice creates a new array. Know when an operation changes the original.

Common mistake

Reading beyond the end returns undefined; sparse arrays can surprise iteration.

Guided challenge

Build a shopping list, add and remove items, then copy it without changing the original.

Run the example

Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.

Completion check

  • Explain the core idea in your own words without reading the code.
  • Change one input and predict the output before running it.
  • Test one boundary or failure case, then record what you changed.