Preparing your workspace
Array methods allow you to express common data operations clearly without manually managing indexes and loops for every task.
Modern JavaScript provides powerful array methods. map creates a new array by transforming every item. filter creates a new array containing items that satisfy a condition. find returns the first matching item. reduce combines array values into a single result. forEach runs a function for each item when you need side effects. These methods are heavily used in frontend applications because UI data often needs to be transformed before rendering. Choosing the right method makes the intention of your code easier to understand.
A dashboard may filter active students, calculate average scores, and create a list of student names before rendering the UI.
const students = [
{ name: 'Aman', score: 90 },
{ name: 'Riya', score: 75 },
{ name: 'Karan', score: 88 }
];
const passed = students.filter(student => student.score >= 80);
const names = students.map(student => student.name);
const total = students.reduce((sum, student) => sum + student.score, 0);
console.log(passed);
console.log(names);
console.log(total);The code produces a filtered student list, an array of names, and the total score.