AWS Builder Center
Building a Student Management System in JavaScript: CRUD Fundamentals

Building a Student Management System in JavaScript: CRUD Fundamentals

A practical guide to implementing a Student Management System in JavaScript using core concepts like higher-order functions (map, filter, find), arrays, objects, and CRUD operations.

Introduction

Building a CRUD (Create, Read, Update, Delete) system is one of the best ways to master JavaScript fundamentals. In this post, I share a simple implementation of a Student Management System that demonstrates how to manipulate state using native array methods and objects.

Core Requirements Covered

  • Variables & Scope:  const ,  let 
  • Control Flow:  if / else 
  • Data Structures: Arrays, Objects
  • Array Methods:  map() ,  find() ,  push() 
  • Functions: Functions and Arrow Functions



Implementation Code

// Adding students adicionarAluno(1, "João Melo", 20, " joao@example.com ", [8.5, 9.0, 7.5]); adicionarAluno(2, "Maria Silva", 22, " maria@example.com ", [10, 9.5, 9.0]);
// Listing students listarAlunos();
// Searching for a student buscarAluno(1);
// Updating student details atualizarAluno(1, { idade: 21 });
// Calculating average grade calcularMedia(1);
// Student Database Array
const alunos = [];
// 1. Create - Add New Student
function adicionarAluno(id, nome, idade, email, notas) {
const novoAluno = {
id,
nome,
idade,
email,
notas
};
alunos.push(novoAluno);
console.log(`Aluno ${nome} cadastrado com sucesso!`);
}
// 2. Read - List All Students
function listarAlunos() {
if (alunos.length === 0) {
console.log("Nenhum aluno encontrado.");
return;
}
const lista = alunos.map((aluno) => ({
id: aluno.id,
nome: aluno.nome,
idade: aluno.idade,
email: aluno.email,
notas: aluno.notas
}));
console.table(lista);
}
// 3. Search - Find Student by ID
function buscarAluno(id) {
const aluno = alunos.find((aluno) => aluno.id === id);
if (aluno) {
console.log("Aluno encontrado:", aluno);
return aluno;
} else {
console.log("Aluno não encontrado.");
return null;
}
}
// 4. Update - Update Student Data
function atualizarAluno(id, novosDados) {
const aluno = alunos.find((a) => a.id === id);
if (aluno) {
Object.assign(aluno, novosDados);
console.log(`Dados do aluno ${aluno.nome} atualizados!`);
return aluno;
} else {
console.log("Aluno não encontrado para atualização.");
return null;
}
}
// 5. Calculate Average Grade
function calcularMedia(id) {
const aluno = alunos.find((a) => a.id === id);
if (aluno && aluno.notas.length > 0) {
const soma = aluno.notas.reduce((acc, nota) => acc + nota, 0);
const media = soma / aluno.notas.length;
console.log(`Média do aluno ${aluno.nome}: ${media.toFixed(2)}`);
return media;
}
return 0;
}
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article