Removing Elements from a Double Linked List using Javascript

Web DevelopmentFront End TechnologyJavascript

Removing an element is very easy in a linked list. We just need to get rid of the node we want to remove, ie, lose its reference. There are 3 cases we need to consider −

  • Removing an element from head: In this case, we can simply assign head = and remove the previous link from the next element. This way we'll lose the reference of the first element. And out head will start pointing to the second element.
  • Removing an element from the tail: In this case, we can simply assign the of second last node to be null and we'll get rid of the last element from the list. We also update the tail to point to a current node.
  • Removing an element from in between: This is more tricky. In this case, we'll have to make the node before the node we want to remove, to directly point to the node after the node we want to remove. So, = and = prevNode will do this for us.

Now let's see an illustration of this −

Now let's have a look at how we'll implement this − 


remove(data, position = 0) {
   if (this.length === 0) {
      console.log("List is already empty");
   let currNode = this.head;
   if (position <= 0) {
      this.head =;
      this.head.prev = null;
   else if (position >= this.length - 1) {
      this.tail = this.tail.prev; = null;
   else {
      let iter = 0;
      while (iter < position) {
         currNode =;
      } =; = currNode;
   return currNode;


You can test this using −

let list = new LinkedList();
list.insert(15, 2);


This will give the output −

20 <->
30 <->
30 <->
15 <->
Published on 27-Jun-2018 14:47:09