forEach dùng để duyệt mảng và thực hiện side effect — không trả về mảng mới nên không tốn thêm bộ nhớ cấp phát.
map tạo và trả về mảng mới cùng độ dài, tốn thêm bộ nhớ do phải cấp phát mảng — dùng khi cần biến đổi dữ liệu. reduce tích lũy các phần tử thành một giá trị duy nhất (số, object, hoặc mảng khác) — linh hoạt nhất nhưng khó đọc nếu logic phức tạp. Về hiệu năng: forEach nhanh nhất do không cấp phát mảng mới; map chậm hơn một chút. Quy tắc chọn: chỉ duyệt thì dùng forEach; biến đổi dữ liệu thì dùng map; tích lũy giá trị thì dùng reduce.
forEach iterates an array and performs side effects — it returns nothing, so no additional memory is allocated for a new array.
map creates and returns a new array of the same length — slightly slower due to array allocation; use it when transforming data. reduce accumulates elements into a single value (number, object, or another array) — the most flexible but can be hard to read with complex logic. Performance-wise: forEach is fastest since it skips array allocation; map is marginally slower. Rule of thumb: use forEach for side effects, map for data transformation, reduce for accumulation.