Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
JavaScript

JavaScript: Master Array Methods for Data Manipulation

- 24.06.26 - ErcanOPAK

πŸ“Š Arrays Are Everywhere

Lists of data need manipulation. Array methods filter, map, reduce, sort. Essential for data processing.

πŸ“ Common Array Methods

// forEach: Iterate
const numbers = [1, 2, 3, 4, 5];
numbers.forEach(n => console.log(n));

// map: Transform each element
const doubled = numbers.map(n => n * 2);  // [2, 4, 6, 8, 10]

// filter: Keep matching elements
const evens = numbers.filter(n => n % 2 === 0);  // [2, 4]

// reduce: Accumulate
const sum = numbers.reduce((acc, n) => acc + n, 0);  // 15

// find: First match
const firstEven = numbers.find(n => n % 2 === 0);  // 2

// findIndex: Index of first match
const evenIndex = numbers.findIndex(n => n % 2 === 0);  // 1

// some: Any match
const hasEven = numbers.some(n => n % 2 === 0);  // true

// every: All match
const allEven = numbers.every(n => n % 2 === 0);  // false

// sort: Sort (with comparator)
const sorted = numbers.sort((a, b) => a - b);  // Ascending

// includes: Check existence
const hasThree = numbers.includes(3);  // true

🎯 Real-World Examples

// Filter active users
const activeUsers = users.filter(u => u.isActive);

// Get user names
const userNames = users.map(u => u.name);

// Sort by age
const sortedByAge = users.sort((a, b) => a.age - b.age);

// Calculate average age
const avgAge = users.reduce((sum, u) => sum + u.age, 0) / users.length;

// Group by category
const grouped = users.reduce((acc, user) => {
  if (!acc[user.role]) acc[user.role] = [];
  acc[user.role].push(user);
  return acc;
}, {});

// Find admin users
const admin = users.find(u => u.role === 'admin');

// Check if any admin
const hasAdmin = users.some(u => u.role === 'admin');

// Get unique values
const unique = [...new Set(numbers)];

πŸ’‘ Chaining Methods

  • Chain methods for cleaner code
  • filter β†’ map β†’ sort β†’ reduce
  • Avoid multiple loops (performance)
  • Use breakpoints to debug chains

“Array methods replaced for loops. Cleaner, more readable. filter, map, reduce are essential JavaScript tools.”

β€” JavaScript Developer

Related posts:

How to disable ASP.Net button after click to prevent double clicking

JS β€œUndefined Is Not Null” β€” The Bug That Breaks APIs

JavaScript β€” Object.freeze() Is Shallow

Post Views: 3

Post navigation

HTML: Use Anchor Tag for Links and Navigation
Ajax: Use Query Strings to Pass Data in GET Requests

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com