Build your own Linked List in JS

I am trying to improve my hold on data structures and algorithms so, I implemented my own linked list class JavaScript. I've shared the API here and tell me if any other methods should be implemented.

Try implementing it on your own as I also was afraid of linked lists using the .next, .next each time. Implementing it really increased my confidence to use linked lists as a data structure.

API's implemented:

size() - returns number of data elements in list
empty() - bool returns true if empty
value_at(index) - returns the value of the nth item (starting at 0 for first)
push_front(value) - adds an item to the front of the list
pop_front() - remove front item and return its value
push_back(value) - adds an item at the end
pop_back() - removes end item and returns its value
front() - get value of front item
back() - get value of end item
insert(index, value) - insert value at index, so current item at that index is pointed to by new item at index
erase(index) - removes node at given index
value_n_from_end(n) - returns the value of the node at nth position from the end of the list
reverse() - reverses the list
remove_value(value) - removes the first item in the list with this value

Link to the
I am trying to improve my hold on data structures and algorithms please tell me if you have any good resources available in the comments below.

If you find any error in my code please raise a pull request in my

Ajit Singh

Ajit Singh