A TypeScript array-like doubly linked list.
An array-like doubly linked list implementation for TypeScript. It mirrors common Array usage patterns while keeping efficient linked-list node operations and for...of iteration support.
pnpm add @nuintun/linked-list
# or
npm i @nuintun/linked-listimport { LinkedList } from '@nuintun/linked-list';
const list = new LinkedList<number>([1, 2, 3]);
list.push(4); // [1, 2, 3, 4]
list.unshift(0); // [0, 1, 2, 3, 4]
console.log(list.at(-1)); // 4
console.log(list.length); // 5
console.log([...list]); // [0, 1, 2, 3, 4]- Array-like mutation methods:
push / pop / shift / unshift / splice / slice / concat - Lookup methods:
at / includes / indexOf / lastIndexOf / find / findIndex - Functional methods:
map / filter / every / some / forEach - Iteration & conversion:
values / Symbol.iterator / valueOf / toString / join - Full TypeScript type support
For method semantics, see MDN Array docs: MDN Array API
new LinkedList<T>(iterable?: Iterable<T>)
unshift(...values: T[]): numbershift(): T | undefinedpush(...values: T[]): numberpop(): T | undefinedsplice(fromIndex: number, removedLength?: number, ...values: T[]): T[]reverse(): LinkedList<T>
at(index: number): T | undefinedincludes(value: T, fromIndex?: number): booleanindexOf(value: T, fromIndex?: number): numberlastIndexOf(value: T, fromIndex?: number): numberfind(callback, context?): T | undefinedfindIndex(callback, context?): numberslice(fromIndex?: number, toIndex?: number): LinkedList<T>concat(...sources: LinkedList<T>[]): LinkedList<T>get length(): number
forEach(callback, context?): voidmap<U>(callback, context?): LinkedList<U>filter(callback, context?): LinkedList<T>every(callback, context?): booleansome(callback, context?): booleanjoin(separator?: string): stringvalues(): Iterator<T>[Symbol.iterator](): Iterator<T>valueOf(): T[]toString(): string
export interface Callback<T, R = boolean> {
(value: T, index: number, source: LinkedList<T>): R;
}