
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
node-linkedlist
Advanced tools
An implementation of the concept of double linked lists.
Quick example to get an instance of the linked list:
var LinkedList = require('node-linkedlist')
, User = require('../Object/User')
, list = LinkedList.Create(User);
...
var user = User.Create();
list.add(user, function(err, listObj) {
...
...
});
The number of nodes linked to each other in a row.
Example
var list = require("node-linkedlist").Create()
...
console.log(list.size);
You are not fixed to use ''LinkedList'' as it is with the internal standard node. You can use it to chain
your own business objects too. The only thing you have to do is to extend the standard node object and publish
the constructor of you class to the ''LinkedList'' instance.
To publish your own node class without inherit from the standard node you only have to implement the methods that are described at the
bottom of the documentation under List node
Arguments
dataType (constructor) - The constructor of the class extending the standard node object.return (LinkedList) - The list itself is returned.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create()
, User = require('<path>/User');
list.setDataType(User);
Alternatively you can publish the constructor directly on create the ''LinkedList'' instance.
var LinkedList = require("node-linkedlist")
, User = require('<path>/User')
, list = LinkedList.Create(User);
...
...
It is important to know that if you publish a constructor to the ''LinkedList'' instance after adding nodes all of them are lost because publishing requires to set a new first node of the published constructor. It is planned to realize a mixed-mode of nodes which have implemented a standard interface.
Set a list of nodes.
Arguments
items (array) - A list with single items to set as linked list.callback (function) - The callback function with parameter err and listObj.return (listObj) - The LinkedList instance itself.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create()
, nodes = [
{id: 23, ...},
{id: 54, ...},
{id: 43, ...},
{id: 12, ...},
{id: 87, ...}
];
...
list.setItems(nodes, function(err, listObj) {
if (err) console.log(err);
else {
console.log(listObj.size);
// will output the number "5"
}
});
Add a new node to the end of the list.
Arguments
data (string) - The data to add to the list. It can be a node object too.callback (function) - The callback function with parameter err and listObj.return (listObj) - The LinkedList instance itself.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create()
, node = list.node;
...
list.add({"firstName": "Warden"}, function(err, listObj) {
if (err) console.log(err);
else {
console.log(listObj.size);
}
});
Search a node by one of its properties. If the list contains extended standard nodes it is required to implement
a getter method like ''getFirstName'' or ''getFirstname''.
Arguments
property (string) - The nodes property to search in the value.value (*) - The value to search in the given property.return (node) - The node you searched or null if it can't be found.Example
var LinkedList = require("node-linkedlist")
, User = require('<path>/User')
, list = LinkedList.Create(User);
...
list.searchBy('firstName', "Warden");
Get a node by a given position.
Arguments
position (number) - The position of the node that is wanted. If the position less equal '0' or higher than the list size
the first or last node is returned.raw (boolean) - A flag to get the node itself instead of the value only. Default is false to get only the value.return (Node) - The node at the position or first/last node if the position is less/equal 0 or higher than list size.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var node = list.get(54, true);
Delete a node from given position.
Arguments
position (number) - The position of the node which has to be removed.return (LinkedList) - The list itself is returned.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
list.delete(54, true);
Get the first node of the list.
Arguments
return (node) - The first node in the list.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var firstNode = list.first();
Get the last node of the list.
Arguments
return (node) - The last node in the list.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var firstNode = list.last();
Check if a node is an instance of the internal standard node.
Arguments
node (object) - The node that will be compared with the constructor of the standard node.return (boolean) - True if the given node is a standard node. Otherwise false is returned.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var node = ...;
if (list.isStdNode(node)) {
...
...
}
Removes all nodes from the list.
Arguments
return (LinkedList) - The list itself is returned.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
list.clean();
Converts the list into an array.
Arguments
return (Array) - All nodes in an array.Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var nodes = list.toArray();
...
Get the next node in the list.
Check the existence of a next node.
Get the previous node in the list.
Check the existence of a previous node.
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create()
, node = null;
// Traversing forwards
for(node = list.first(); list.hasNext(); node = list.next()) {
...
...
}
// or backwards
for(node = list.last(); list.hasPrevious(); node.previous()) {
...
...
}
The list node is the standard node object used by the linked list internally if no other node constructor is offered.
You can get it via the property 'node' of the linked list object.
Arguments
Example
var list = require("node-linkedlist").Create()
, node = list.node;
var newNode = node.Create();
Set another node object as next node to the current one.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var last = list.last()
, node = list.node.Create();
node.setValue({
field1: true,
field2: 123,
field3: {success: true},
field4: "Everything's fine."
});
last.setNext(node);
...
Get the next node that is referenced to the current node.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var node = list.first()
...
node = node.next();
...
Check the existence of a next nodes reference.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var node = list.first()
...
if (node.hasNext())
node = node.next();
...
Set another node object as previous node to the current one.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create()
, node = list.node;
...
var last = node.Create()
, newNode = node.Create();
last.setValue({
field1: true,
field2: 123,
field3: {success: true},
field4: "Everything's fine."
});
newNode.setValue("Only a small text string...");
last.setPrevious(newNode);
...
Get the previous node that is referenced to the current node.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var node = list.last()
...
node = node.previous();
...
Check the existence of a previous nodes reference.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create();
...
var node = list.last()
...
if (node.hasPrevious())
node = node.previous();
...
Set the value that has to be added to the list. This method is used internally so it is fully transparent
via ''list.add(...)'' if you use the standard node.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create()
, Node = list.node;
...
var node = list.last()
...
var newNode = Node.Create();
newNode.setValue({message: 'Created new node.'});
node.setNext(newNode);
...
Get the value that is stored in a node. This method is used internally so it is fully transparent
via ''list.get(position)'' if you use the standard node.
Arguments
Example
var LinkedList = require("node-linkedlist")
, list = LinkedList.Create()
, Node = list.node;
...
var node = list.last()
console.log(node.getValue());
...
FAQs
Double linked list features
We found that node-linkedlist demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.