RivoCode

JavaScript Fundamentals · Arrays · Lesson 17 of 48

Array Methods: push, pop, map

Concept

Array Methods: push, pop, map

push and pop add or remove items from the end of an array. map creates a new array by transforming each item.

Unlike push and pop, map never changes the original array — it always returns a brand new one, which makes it safer to use when other code still relies on the original.

By the end of this lesson
  • Explain the core idea behind Array Methods: push, pop, map.
  • Predict output before running a change.
  • Test one realistic and one unusual input.
  • Use the result to make the next decision.
How to study this page
  1. 1. Read one concept.
  2. 2. Change the example.
  3. 3. Run, compare, and explain.
  4. 4. Complete the challenge below.
Syntax
array.push(item)
array.pop()
array.map((item) => transformedItem)
ExampleRunnable
const nums = [1, 2, 3];
nums.push(4);
const doubled = nums.map((n) => n * 2);
console.log(doubled);
Try it Yourself »
unshift and shift for the front of the array
const nums = [2, 3];
nums.unshift(1);
console.log(nums);
nums.shift();
console.log(nums);
Note: unshift adds to the start and shift removes from the start — the mirror image of push and pop.
Self-check before continuing

Without looking at the example, describe what changes when you modify one input in Array Methods: push, pop, map. Then reopen the editor and prove your explanation with a small test.

You are ready to continue when you can predict, test, and explain the result.

Your turn

Use map to turn an array of names into an array of greeting strings.

Loading editor…

Console

Output will appear here...