Skip to content

Repository files navigation

# JavaScript Array HOF```jsconstusers= [
{ name:'A', age:24, role:'admin' },
{ name:'B', age:20, role:'user' },
{ name:'A', age:30, role:'user' }
];

1. filter():- Returns: Array , many data

Q. : “Give me ALL matching items”

constresult=users.filter(user=>user.name==='A');

2. find():- One object OR undefined

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


3. map():- Array

Q. : “Change data, same length”

constresult=users.map(user=>user.name='ChangeName');

4. forEach():- Nothing

Q. : “Just do something, don’t return”

constnames=[];users.forEach(user=>{names.push(user.name);});
users.forEach(user=>{user.isActive=true;});

5. some():- boolean

Q. : “Is there AT LEAST ONE?”

constresult=users.some(user=>user.age>25);

6. every(): boolean

Q. : “Are ALL matching?”

constresult=users.every(user=>user.age>18);

7. reduce():- Anything

Returns:Q. : “Combine everything into one”

consttotalAge=users.reduce((sum,user)=>{returnsum+user.age;},0);

8. sort():- Array (same one, modified)

Q. : “Order the data”

users.sort((a,b)=>a.age-b.age);

Super Easy Memory Line (Read Daily)

filter → many find → one map → change forEach → nothing some → any every → all reduce → combine sort → order

About

A focused JavaScript repository dedicated to strengthening logic-building and problem-solving skills. It contains concise, well-structured solutions to common programming challenges, covering core concepts such as loops, conditionals, arrays, objects, functions, and basic algorithms. The goal is to build a strong foundation in JavaScript.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages