A comprehensive JavaScript implementation of the Linked List data structure with full test coverage and practical examples.
This project implements a Linked List data structure in JavaScript as part of The Odin Project Full Stack JavaScript curriculum. While JavaScript arrays are dynamic and flexible, understanding linked lists provides a solid foundation for learning more complex data structures like graphs and binary trees.
A linked list is a linear collection of data elements called nodes, where each node contains:
- A value (the data)
- A pointer to the next node in the sequence
This implementation uses ES6 modules and is compatible with Node.js v22+.
Key Concepts:
- Dynamic data structure that grows and shrinks at runtime
- Efficient insertion and deletion at any position
- No need for contiguous memory allocation
- Foundation for understanding more complex data structures
- Core Operations - append, prepend, insert, remove, and traverse nodes
- Index-based Access - retrieve nodes by position with
at(index) - Search Operations - find values and their indices with
contains()andfindIndex() - Flexible Insertion - insert multiple values at any index with
insertAt() - String Representation - visualize the list with
toString() - ES6 Module Support - modern JavaScript syntax with import/export
- Comprehensive Examples - practical usage demonstrations in
main.js - Error Handling - proper boundary checks and error messages
Before you begin, ensure you have met the following requirements:
- Node.js
>= 22.0.0- Download here - Git - For version control
- A code editor (VS Code, Sublime Text, etc.)
git clone https://github.com/top-submissions/fullstackjs-linked-list.git
cd fullstackjs-linked-listThis project has no external dependencies and runs with vanilla JavaScript.
# If you add testing frameworks or linters later
npm installimport { LinkedList } from './LinkedList.js';
// Create a new linked list
const list = new LinkedList();
// Add elements
list.append("dog");
list.append("cat");
list.prepend("bird");
// Display the list
console.log(list.toString());
// Output: ( bird ) -> ( dog ) -> ( cat ) -> null
// Get list size
console.log(list.size()); // 3
// Access elements
console.log(list.at(1)); // "dog"
console.log(list.head()); // "bird"
console.log(list.tail()); // "cat"Execute the test file to see the linked list in action:
node main.js// Check if value exists
list.contains("dog"); // true
// Find index of value
list.findIndex("cat"); // 2
// Insert at specific position
list.insertAt(1, "hamster", "snake");
console.log(list.toString());
// ( bird ) -> ( hamster ) -> ( snake ) -> ( dog ) -> ( cat ) -> null
// Remove by index
list.removeAt(2);
console.log(list.toString());
// ( bird ) -> ( hamster ) -> ( dog ) -> ( cat ) -> null
// Remove first element
list.pop(); // Returns "bird"Test your implementation by running:
node main.jsExpected output:
( dog ) -> ( cat ) -> ( parrot ) -> ( hamster ) -> ( snake ) -> ( turtle ) -> null
You can add your own test cases in main.js or create additional test files in the examples/ directory.
- JavaScript ES6+ - Modern JavaScript features (classes, modules)
- Node.js - JavaScript runtime environment
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ for The Odin Project