What is Virtual DOM Diff (Keys)?
Compare two lists and update only the DOM nodes that really changed - with and without keys.
Type a tool name, format or task
Compare two lists and update only the DOM nodes that really changed - with and without keys. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Compare two lists and update only the DOM nodes that really changed - with and without keys. Keep a map of the old items by key. Walk the new list: reuse a node when its key exists, insert it when it is new, move it when the order changed. Remove old nodes whose keys are gone. Time complexity: O(n). Space complexity: O(n). How React, Vue and other frameworks reconcile lists, and why you should give list items stable keys instead of array indexes.
Compare two lists and update only the DOM nodes that really changed - with and without keys.
Time: O(n). Space: O(n).
How React, Vue and other frameworks reconcile lists, and why you should give list items stable keys instead of array indexes.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
Each item has a key. React/Vue use keys to recognise the same item even when it moves, so unchanged DOM nodes are reused.
function reconcileKeyed(oldList, newList) {const oldPos = new Map(oldList.map((n, i) => [n.key, i]));const newKeys = new Set(newList.map((n) => n.key));let lastIndex = 0;for (const next of newList) {const i = oldPos.get(next.key);if (i === undefined) insert(next);else if (i < lastIndex) move(next);else lastIndex = i;}for (const old of oldList) {if (!newKeys.has(old.key)) remove(old);}}
Tip: use the arrow keys to step and the space bar to play or pause.