In-Depth Guide: Modern JavaScript Array Methods

The methods we are about to cover are called Higher-Order Functions. This is a fancy term that simply means they are functions that take another function as an argument (this is the "callback" function you provide).

The Core Idea: Instead of manually writing a for loop every time, you tell the array what you want to do, and the array method handles the looping for you.

Let's use this sample array for our examples:

const products = [
  { id: 1, name: "Laptop", category: "Electronics", price: 1200, inStock: true },
  { id: 2, name: "Book", category: "Books", price: 30, inStock: true },
  { id: 3, name: "Coffee Maker", category: "Appliances", price: 150, inStock: false },
  { id: 4, name: "Headphones", category: "Electronics", price: 200, inStock: true }
];


1. .forEach() - The Simple Looper


2. .map() - The Transformer