0Pricing
JavaScript Academy · Lesson

Declarative Data Transformation

Transform data with map, filter, and reduce.

Declarative vs Imperative

Imperative code says HOW (loops, counters, mutation). Declarative code says WHAT. Array methods like map, filter, and reduce let you describe transformations without manual loops.

const nums = [1, 2, 3, 4];
const doubled = nums.map((n) => n * 2);
console.log(doubled); // [2, 4, 6, 8]

map: Transform Each Element

map returns a new array of the same length with each element transformed by your function. The original is untouched.

const names = ["ada", "bob"];
const upper = names.map((n) => n.toUpperCase());
console.log(upper); // ["ADA", "BOB"]
console.log(names); // unchanged

All lessons in this course

  1. Pure Functions and Side Effects
  2. Declarative Data Transformation
  3. Avoiding Mutation
  4. Point-Free Style
← Back to JavaScript Academy