# JavaScript Array HOF```jsconstusers= [
{ name:'A', age:24, role:'admin' },
{ name:'B', age:20, role:'user' },
{ name:'A', age:30, role:'user' }
];Q. : “Give me ALL matching items”
constresult=users.filter(user=>user.name==='A');Q. : “Give me FIRST matching item”
constresult=users.find(user=>user.name==='A');forEach is NOT for data transformation. forEach is for SIDE EFFECTS. forEach → change EXISTING data map → create NEW data
Q. : “Change data, same length”
constresult=users.map(user=>user.name='ChangeName');Q. : “Just do something, don’t return”
constnames=[];users.forEach(user=>{names.push(user.name);});users.forEach(user=>{user.isActive=true;});Q. : “Is there AT LEAST ONE?”
constresult=users.some(user=>user.age>25);Q. : “Are ALL matching?”
constresult=users.every(user=>user.age>18);Returns:Q. : “Combine everything into one”
consttotalAge=users.reduce((sum,user)=>{returnsum+user.age;},0);Q. : “Order the data”
users.sort((a,b)=>a.age-b.age);filter → many find → one map → change forEach → nothing some → any every → all reduce → combine sort → order