Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

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: Building a Task Management App with Array Methods

- 15.08.26 - ErcanOPAK

📋 Task Management = Array Methods

Task management needs data manipulation. JavaScript array methods make it easy to manage tasks.

📝 Task Management

class TaskManager {
    constructor() {
        this.tasks = [];
        this.id = 0;
    }

    // CRUD Operations
    addTask(title, priority = 'medium') {
        const task = {
            id: ++this.id,
            title,
            priority,
            completed: false,
            createdAt: new Date()
        };
        this.tasks.push(task);
        return task;
    }

    getTasks() {
        return this.tasks;
    }

    getTask(id) {
        return this.tasks.find(task => task.id === id);
    }

    updateTask(id, updates) {
        const task = this.getTask(id);
        if (task) {
            Object.assign(task, updates);
            return task;
        }
        return null;
    }

    deleteTask(id) {
        const index = this.tasks.findIndex(task => task.id === id);
        if (index !== -1) {
            return this.tasks.splice(index, 1)[0];
        }
        return null;
    }

    // Query Operations
    getCompletedTasks() {
        return this.tasks.filter(task => task.completed);
    }

    getPendingTasks() {
        return this.tasks.filter(task => !task.completed);
    }

    getTasksByPriority(priority) {
        return this.tasks.filter(task => task.priority === priority);
    }

    sortTasksByPriority() {
        const order = { high: 0, medium: 1, low: 2 };
        return [...this.tasks].sort((a, b) => order[a.priority] - order[b.priority]);
    }

    getTaskSummary() {
        const summary = this.tasks.reduce((acc, task) => {
            if (task.completed) {
                acc.completed++;
            } else {
                acc.pending++;
            }
            return acc;
        }, { completed: 0, pending: 0 });
        
        return summary;
    }

    searchTasks(query) {
        const searchTerm = query.toLowerCase();
        return this.tasks.filter(task => 
            task.title.toLowerCase().includes(searchTerm)
        );
    }

    groupByPriority() {
        return this.tasks.reduce((acc, task) => {
            if (!acc[task.priority]) {
                acc[task.priority] = [];
            }
            acc[task.priority].push(task);
            return acc;
        }, {});
    }

    getRecentTasks(days = 7) {
        const cutoff = new Date();
        cutoff.setDate(cutoff.getDate() - days);
        return this.tasks.filter(task => 
            task.createdAt >= cutoff
        );
    }
}

🎯 UI Integration

// Render Tasks
function renderTasks(tasks) {
    const container = document.getElementById('task-list');
    container.innerHTML = tasks.map(task => `
        
${task.title} ${task.priority}
`).join(''); } // Task Statistics function updateStats(tasks) { const total = tasks.length; const completed = tasks.filter(t => t.completed).length; const pending = total - completed; document.getElementById('total-tasks').textContent = total; document.getElementById('completed-tasks').textContent = completed; document.getElementById('pending-tasks').textContent = pending; document.getElementById('completion-rate').textContent = total ? Math.round((completed / total) * 100) + '%' : '0%'; } // Filter Tasks function filterTasks(filter) { let filtered = manager.getTasks(); switch(filter) { case 'completed': filtered = manager.getCompletedTasks(); break; case 'pending': filtered = manager.getPendingTasks(); break; case 'high': filtered = manager.getTasksByPriority('high'); break; } renderTasks(filtered); }

💡 Task Management Tips

  • Use array methods for data manipulation
  • Keep state management simple
  • Update UI reactively
  • Use localStorage for persistence
  • Handle edge cases gracefully

Array methods make data manipulation elegant and readable. They’re essential for building interactive applications.

— Frontend Developer

Related posts:

JavaScript Performance: The One Weird Trick That Made Our App 10x Faster

JavaScript Performance: The One Weird Trick That Made Our App 10x Faster

JavaScript: Fix FinalizationRegistry Cleanup Entries That Stop Arriving Entirely Because the Registr...

JavaScript: Fix FinalizationRegistry Cleanup Entries That Stop Arriving Entirely Because the Registr...

JavaScript: Fix Array.prototype.at() Returning Undefined for a Valid Negative Index Because an Old P...

JavaScript: Fix Array.prototype.at() Returning Undefined for a Valid Negative Index Because an Old P...

Views: 7

Post navigation

HTML: Building Custom Components with Web Components
AJAX: Caching Strategies for REST APIs

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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