This tutorial shows how to do this but I don't really understand the intention to create this.start and this.end variables inside the tutorial.

The tutorial uses a List wrapper around that recursive structure with some helper methods. It says: "It is possible to avoid having to record the end of the list by performing a traverse of the entire list each time you need to access the end - but in most cases storing a reference to the end of the list is more economical."

This code gives me an infinite loop of array[0].

Not really, but it creates a circular reference with the line list.rest = list;. Probably the code that is outputting your list chokes on that.

What's wrong is with my code?

You need to create multiple objects, define the object literal inside the loop body instead of assigning to the very same object over and over! Also, you should access array[i] inside the loop instead of array[0] only:

function arrayToList(array){
    var list = null;
    for (var i=array.length-1; i>=0; i--)
        list = {value: array[i], rest:list};
    return list;
}
Answer from Bergi on Stack Overflow
๐ŸŒ
Mozilla
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Guide โ€บ Data_structures
JavaScript data types and data structures - JavaScript | MDN
Programming languages all have built-in data structures, but these often differ from one language to another. This article attempts to list the built-in data structures available in JavaScript and what properties they have. These can be used to build other data structures.
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ javascript-data-structures
8 Common JavaScript Data Structures | Built In
JavaScript Data Structures: Getting Started. | Video: Academind ... A hash table is a key-value data structure. Due to the lightning speed of querying a value through a key, hash tables are commonly used in map, dictionary or object data structures. As shown in the graph above, the hash table uses a hash function to convert keys into a list ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ data-structures-in-javascript-with-examples
Data Structures in JavaScript โ€“ With Code Examples
September 11, 2024 - Arrays are useful when we have to store individual values and add/delete values from the end of the data structure. But when we need to add/delete from any part of it, there are other data structures that perform more efficiently (we'll talk about them later on). In JavaScript, an object is a collection of key-value pairs.
๐ŸŒ
GitHub
github.com โ€บ trekhleb โ€บ javascript-algorithms
GitHub - trekhleb/javascript-algorithms: ๐Ÿ“ Algorithms and data structures implemented in JavaScript with explanations and links to further readings
This repository contains JavaScript based examples of many popular algorithms and data structures.
Starred by 196K users
Forked by 31.1K users
Languages ย  JavaScript
๐ŸŒ
Educative
educative.io โ€บ blog โ€บ javascript-data-structures
6 JavaScript data structures you must know
What are data structures?Types of Javascript data structuresData structure 1: ArrayAdvantages of ArrayDisadvantages of ArrayApplications of ArrayData structure 2: QueuesAdvantages of QueuesDisadvantages of QueuesApplications of QueuesData structure 3: Linked listAdvantages of linked listDisadvantages of linked listApplications of linked listData structure 4: TreesAdvantages of trees Disadvantages of trees Applications of treesData structure 5: GraphsAdvantages of graphsDisadvantages of graphsApplications of graphsData structure 6: Hash tables (map)Advantages of hash tablesDisadvantages of hash tablesApplications of hash tablesData structures comparison tableWhat to learn nextContinue reading about JavaScript
๐ŸŒ
DEV Community
dev.to โ€บ nehasoni__ โ€บ 7-javascript-data-structures-you-must-know-57ah
7 JavaScript Data Structures you must know - DEV Community
May 14, 2021 - It is the base of IT industries and is largely used in the areas of Artificial Intelligence, operating systems, graphics, etc. In this blog post, I will cover the seven most used JavaScript data structures that every JS developer should know. - What are Data Structures? - 7 most used data structures - Arrays - Stack - Queues - Linked List - Trees - Graphs - Hashtable
Top answer
1 of 3
3

This tutorial shows how to do this but I don't really understand the intention to create this.start and this.end variables inside the tutorial.

The tutorial uses a List wrapper around that recursive structure with some helper methods. It says: "It is possible to avoid having to record the end of the list by performing a traverse of the entire list each time you need to access the end - but in most cases storing a reference to the end of the list is more economical."

This code gives me an infinite loop of array[0].

Not really, but it creates a circular reference with the line list.rest = list;. Probably the code that is outputting your list chokes on that.

What's wrong is with my code?

You need to create multiple objects, define the object literal inside the loop body instead of assigning to the very same object over and over! Also, you should access array[i] inside the loop instead of array[0] only:

function arrayToList(array){
    var list = null;
    for (var i=array.length-1; i>=0; i--)
        list = {value: array[i], rest:list};
    return list;
}
2 of 3
3

This particular data structure is more commonly called cons. Recursion is the most natural (not necessarily the most efficient) way to work with conses. First, let's define some helper functions (using LISP notation rather than "value/rest"):

function cons(car, cdr) { return [car, cdr] }
function car(a) { return a[0] }
function cdr(a) { return a[1] }

Now, to build a cons from an array, use the following recursive statement:

cons-from-array = cons [ first element, cons-from-array [ the rest ] ]

In Javascript:

function arrayToList(array) {
    if(!array.length)
        return null;
    return cons(array[0], arrayToList(array.slice(1)));
}

And the reverse function is similarly trivial:

function listToArray(list) {
    if(!list)
        return [];
    return [car(list)].concat(listToArray(cdr(list)));
}
๐ŸŒ
Eloquent JavaScript
eloquentjavascript.net โ€บ 04_data.html
Data Structures: Objects and Arrays :: Eloquent JavaScript
As generic blobs of values, objects can be used to build all sorts of data structures. A common data structure is the list (not to be confused with arrays).
Find elsewhere
๐ŸŒ
Profy.dev
profy.dev โ€บ article โ€บ javascript-data-structures
Data Structures In Frontend JavaScript In The Real World (With React Code Examples)
Never seen a linked list in frontend JavaScript code? Me neither. But here are real-world examples of data structures Map, Set, Stack, Queue, and Tree.
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ know your javascript data structures
Know your JavaScript data structures - LogRocket Blog
June 4, 2024 - There are lots of methods you can add to your linked list, but the above sets down the core fundamentals that you need to know. So the second-to-last data structure we are tackling is the mighty hash table. I purposefully placed this after the LinkedList explanation, as they are not a million miles away from each other. A hash table is a data structure that implements an associative array, which means it maps keys to values. A JavaScript object is a hash table, as it stores key-value pairs.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ 8 common data structures in javascript
8 Common Data Structures in JavaScript You Should Know | Simplilearn
January 26, 2025 - Data structures are formats in Javascript that help access the data in more efficient ways. In this article, we will discuss some common types of data Structures used in javascript. Click here to know more.
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ learn-data-structures-with-javascript-dsa-tutorial
DSA in JavaScript - GeeksforGeeks
October 10, 2025 - This beginner-friendly guide covers Data Structures and Algorithms (DSA) in JavaScript, including built-in structures like arrays, strings, Map, Set, and user-defined structures such as linked lists, stacks, queues, trees, heaps, and graphs.
๐ŸŒ
Medium
medium.com โ€บ @catherineisonline โ€บ javascript-for-beginners-data-structures-ce8d85bb2d5c
JavaScript for Beginners: Data Structures | by Ekaterine Mitagvaria | Medium
February 5, 2025 - Using an array is great for very simple, minimalistic lists however itโ€™s very weak when it comes to the stability of indices. When you add new items to the start or middle of the array, the index of all items changes so itโ€™s not very good in some cases when you depend on the index and itโ€™s not stable. An object in JavaScript is another data structure ...
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ js โ€บ data-structures โ€บ p โ€บ 1
JavaScript Data Structures - 30 seconds of code
JavaScript provides a handful of native data structures that you can start using in your code right now. ... A queue is a linear data structure which follows a first in, first out (FIFO) order of operations. ... A stack is a linear data structure which follows a last in, first out (LIFO) order of operations. ... A linked list is a linear data structure where each element points to the next.
๐ŸŒ
Codemotion
codemotion.com โ€บ home โ€บ frontend โ€บ javascript โ€บ 7 javascript data structures for solving real-world problems
JavaScript Data Structures: Use Them To Fix Real World Problems
November 14, 2023 - Sets are also efficient at checking ... specific elements when carrying out big data visualization. A linked list is a type of chained data structure in JavaScript....
๐ŸŒ
Medium
emma-delaney.medium.com โ€บ 7-javascript-data-structures-you-must-know-2a7a0291bdf7
7 JavaScript Data Structures you must know | by Emma Delaney | Medium
December 22, 2023 - Hash tables use a hash function to map keys to indexes, allowing for efficient data retrieval. They are often used to implement arrays, dictionaries, and associative caches. JavaScript objects can be thought of as a form of hash table. Trees are hierarchical data structures with a root node and branches leading to leaf nodes.
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ datastructures-js
datastructures-js - npm
const { Stack, Queue, Deque, EnhancedSet, LinkedList, LinkedListNode, DoublyLinkedList, DoublyLinkedListNode, Heap, MinHeap, MaxHeap, PriorityQueue, MinPriorityQueue, MaxPriorityQueue, BinarySearchTree, BinarySearchTreeNode, AvlTree, AvlTreeNode, Trie, TrieNode, Graph, DirectedGraph, } = require('datastructures-js');
      ยป npm install datastructures-js
    
Published ย  Jun 20, 2023
Version ย  13.0.0
Author ย  Eyas Ranjous
๐ŸŒ
AlmaBetter
almabetter.com โ€บ bytes โ€บ articles โ€บ data-structures-in-javascript
Common Data Structures in JavaScript - With Code Examples
October 16, 2023 - Adjacency lists and adjacency matrices are common representations for graphs. Strings: Strings in JavaScript are essentially sequences of characters and can be manipulated using built-in methods for string operations. WeakMap and WeakSet: These are specialized versions of Map and Set that allow for more efficient garbage collection by not preventing objects from being collected if they're only referenced by these structures. JavaScript's built-in data structures provide a solid foundation for managing and organizing data within the language.