Data Structure
data structures, collection typeDefinition
A way of arranging data in memory that makes some operations cheap and others expensive — an array, a linked list, a hash map, a set, a stack, a queue, a tree, a graph
Choosing one is choosing which question you intend to ask often. An array is fast to read by position and slow to search; a hash map (a JavaScript Map, a plain object) answers is this key present in constant time and has no order; a Set answers have I seen this and refuses duplicates for free. Most front-end performance work that looks like an algorithm problem is a data structure problem — a lookup written as a nested find over an array, run once per row.
The shape you put data in, chosen for the question you will ask it most.
Avoid: reaching for an exotic one first. In application code the
honest shortlist is array, Map, Set — and the common bug is using an
array for all three jobs and then wondering why a list of six hundred
items is slow to render.