JavaScript

Arrays

Master JavaScript arrays! Learn CRUD operations, iteration methods like map, filter, reduce, and array manipulation techniques.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master JavaScript arrays! Learn CRUD operations, iteration methods like map, filter, reduce, and array manipulation techniques. This hands-on tutorial focuses on practical implementation of arrays concepts.

Arrays

Arrays are one of the most important data structures in JavaScript. They allow you to store multiple values in a single variable.

1. What are Arrays? πŸ“¦

What is it? An ordered list of values. Each value is called an "element" and has a numeric position called an "index".

Why use it? To store lists of data (e.g., a shopping list, user IDs, or colors) without creating separate variables for each item.

How it works: Arrays are zero-indexed, meaning the first item is at index 0.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

2. Basic Methods (Add/Remove) βž•βž–

JavaScript provides built-in methods to add or remove items easily.

  • push(): Add to end
  • pop(): Remove from end
  • unshift(): Add to start
  • shift(): Remove from start
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

3. Iterating Arrays πŸ”„

How do you go through every item in an array?

forEach (Execute code for each item)

Great for side effects (printing, saving to DB).

map (Transform items)

Creates a new array by changing each item.

filter (Select items)

Creates a new array with only items that pass a test.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

4. The reduce Method πŸ’ͺ

What is it? The most powerful array method. It takes an array and "reduces" it to a single value (e.g., a sum, an object, or a number).

How it works: It loops through the array, maintaining an "accumulator" (running total).

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

5. Searching & Sorting πŸ”

  • find(): Returns the first item that matches.
  • includes(): Returns true if item exists.
  • sort(): Sorts the array (converts to string by default!).
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

Practical Example: Shopping Cart πŸ›’

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "JavaScript arrays, push, pop, map, filter, reduce, and sorting"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 4

Which method creates a NEW array with transformed elements?

forEach
map
filter
reduce

Key Takeaways

βœ… Arrays are ordered lists (0-indexed).
βœ… push/pop add/remove from end.
βœ… map transforms, filter selects.
βœ… reduce combines everything into one value.
βœ… sort needs a compare function for numbers.

What's Next?

Arrays are powerful, but modern JavaScript gives us even better tools. Next, we'll learn Spread, Rest, and Destructuring!

Keep coding! πŸš€