Back to Cheat Sheets

Writing

JavaScript for Beginners Series - Part 8 (English & Darija)

Part 8 of the JavaScript for Beginners series by Ibtissam Oulahchoum. Master the essential Array Methods: .map(), .filter(), and .reduce(). These Higher Order Functions are the key to writing clean, modern JavaScript (especially for React) and replacing traditional loops. Includes simplified explanations in Moroccan Darija.

JavaScript Array Methods React Web Development Darija Functional Programming

January 23, 2026 · 2 min read

JavaScript for Beginners Series - Part 8 (English & Darija)

Introduction

Welcome to Part 8 of the JavaScript for Beginners Series. In this part, we explore Array Methods. In modern JavaScript (and especially in React), we rarely use for loops to process lists. Instead, we use Higher Order Functions that result in cleaner, more readable code.

  • Darija: هاد الـ Methods بـ 3 هوما الساروت باش تخدم بـ Arrays بطريقة احترافية (Functional Programming). فـ React، غادي تخدم بيهم بزاف باش تأفيشي (Display) القوائم.

1. .map() (Transform)

Creates a new array by applying a function to every element in the calling array. It is used to transform data (e.g., converting raw data into HTML).

  • Darija: كتخدم بيها إيلا بغيتي تدوز على الـ Elements كاملين وتبدل فيهم شي حاجة (مثلاً عندك قائمة د الأسعار وبغيتي تزيد عليهم الضريبة). هي "كتحول" الداتا من شكل لشكل آخر.

2. .filter() (Select)

Creates a new array with only the elements that pass a specific test (return true).

  • Darija: كتخدم بيها إيلا بغيتي "تصفي" الداتا. كتقول ليها "عطيني غير المنتوجات اللي الثمن ديالهم كبر من 200 درهم"، وهي كترجع ليك Array جديد فيه غير داكشي اللي بغيتي.

3. .reduce() (Accumulate)

Executes a reducer function on each element, resulting in a single output value (like a sum).

  • Darija: كتجمع ليك الحساب كامل فـ قيمة وحدة (مثلاً إيلا بغيتي تحسب الطوطال ديال شي Panier).

Code Examples

Here is how you use them in practice:

const prices = [100, 200, 300, 400];

// 1. MAP: Double the prices
// Returns a NEW array, does not change the original
const doubled = prices.map(price => price * 2);
console.log(doubled); // Output: [200, 400, 600, 800]

// 2. FILTER: Get prices above 250
const expensive = prices.filter(price => price > 250);
console.log(expensive); // Output: [300, 400]

// 3. REDUCE: Calculate the Total
// 'acc' is the accumulator (total), 'curr' is the current item
// '0' is the initial value
const total = prices.reduce((acc, curr) => acc + curr, 0);
console.log(total); // Output: 1000

Related Cheat Sheets

Mentorship

Want to learn, not just read?

These cheat sheets are the short version. If you want the long one, I teach — one on one, at your pace, on what you are actually trying to build.

Let's talk
  • Learn with guidance

    I will walk you through the fundamentals, review your code, and help you grow past the tutorials.

  • Choose your career path

    Not sure which direction to take? We will talk it through and map a path that fits your strengths and your goals.

Want to work together?

I'm always open to discussing new projects.

Get in Touch