Let’s Implement LinkedList in JavaScript !!

Baisali Pradhan
3 min readJul 24, 2022

LinkedList is a type of linear data Structure which is a collection of nodes. In a node, 1st part describes the data and the next part point to the next node’s address.

Unlike in an array, the elements or nodes in LinkedList are not stored in a sequential memory location. Instead, the elements are linked together using pointers.

The 1st part of the 1st node is known as HEAD. and each node has 2 things:

  1. Data
  2. A pointer to the next element

And the pointer of the last node refers to NULL.

Types:
Singly LL
Doubly LL
Circular LL
Circular Doubly LL

Implementation of Singly LinkedList:

Here n1 has some value i.e. 123 and n2 has some value i.e. 120. If we want to link n1 and n2 then we can use the next property. And if we print the value of n1 then it will print:
{ data: 123, next { data: 120 } }

Output :

Here next is null because we didn’t mention the value of the next node.

Insert at 1st Index:

Insert At Last Index:

Insert at an Index:

Get data from an Index :

Remove at an index:

Clear All the Data & Print all the Data:

You can find the full implementation code here.

Thank you for reading this article. If anything is wrong then please let me know.

N.B: I wrote these articles only for my better understanding

--

--