State

Sort array state safely

Copy the array before using a mutating sort; shared records should still be treated as read-only.

Formal Syntax & Structure

react syntaxreact
[...items].sort(compare)

Working Example

Example Snippetreact
const ascending = [...numbers].sort((a, b) => a - b);
React Reference