JavaScript Curriculum
Lists of Things
mediumNexus has 847 products. Your manager wants a page showing only the active ones, with prices formatted and names in uppercase. You have all 847 in a database. You could write 847 console.log calls. Or you could write three lines using array methods that do it automatically — for 847 items or 8 million.
One variable, many values
So far every variable holds a single thing. But real data comes in collections: a list of products, a set of users, a queue of notifications.
An array is an ordered list of values stored in a single variable. Each value sits at a numbered position called an index.
Click any slot to read it by index:
Indexes start at 0. Last item is at index 3.
Creating and reading arrays
The three methods you'll use constantly
JavaScript arrays come with dozens of built-in methods. These three handle 90% of real-world work:
Transform every item — returns a NEW array of the same length.
input array
result — new array (same length)
The pattern with all three is identical: you pass in a callback function that receives each item, and the method handles the looping for you.
Mutation vs immutability — the difference that matters
Some array methods change the original array in place (mutate). Others return a new array and leave the original untouched. This distinction becomes critical when you're working with React state or shared data.
current array
⚠️ mutates original
✓ returns new array
In modern JavaScript — especially in React — prefer the non-mutating versions. Your code becomes easier to reason about when arrays don't change unexpectedly.
Iterating with forEach
When you want to run code for each item but don't need a new array back, use forEach:
forEach always returns undefined. Use it for side effects (logging, updating the DOM, sending requests) — not for building new arrays.
Working with arrays of objects
Real data isn't arrays of plain strings. It's arrays of objects — each item a package of related properties:
That three-step pipeline — filter → map → forEach — is the backbone of data transformation in JavaScript.
Challenge
You have an array of product objects. Each has a name (string), price (number), and active (boolean). Write code to: (1) use filter to get only active products, (2) use map on the result to build formatted strings like \"Nexus — $9.50\", (3) log each formatted string. Use the products array provided in the starter code.
Lists of Things
mediumNexus has 847 products. Your manager wants a page showing only the active ones, with prices formatted and names in uppercase. You have all 847 in a database. You could write 847 console.log calls. Or you could write three lines using array methods that do it automatically — for 847 items or 8 million.
One variable, many values
So far every variable holds a single thing. But real data comes in collections: a list of products, a set of users, a queue of notifications.
An array is an ordered list of values stored in a single variable. Each value sits at a numbered position called an index.
Click any slot to read it by index:
Indexes start at 0. Last item is at index 3.
Creating and reading arrays
The three methods you'll use constantly
JavaScript arrays come with dozens of built-in methods. These three handle 90% of real-world work:
Transform every item — returns a NEW array of the same length.
input array
result — new array (same length)
The pattern with all three is identical: you pass in a callback function that receives each item, and the method handles the looping for you.
Mutation vs immutability — the difference that matters
Some array methods change the original array in place (mutate). Others return a new array and leave the original untouched. This distinction becomes critical when you're working with React state or shared data.
current array
⚠️ mutates original
✓ returns new array
In modern JavaScript — especially in React — prefer the non-mutating versions. Your code becomes easier to reason about when arrays don't change unexpectedly.
Iterating with forEach
When you want to run code for each item but don't need a new array back, use forEach:
forEach always returns undefined. Use it for side effects (logging, updating the DOM, sending requests) — not for building new arrays.
Working with arrays of objects
Real data isn't arrays of plain strings. It's arrays of objects — each item a package of related properties:
That three-step pipeline — filter → map → forEach — is the backbone of data transformation in JavaScript.
Challenge
You have an array of product objects. Each has a name (string), price (number), and active (boolean). Write code to: (1) use filter to get only active products, (2) use map on the result to build formatted strings like \"Nexus — $9.50\", (3) log each formatted string. Use the products array provided in the starter code.