Widely availableSupported across all major browsers. Safe to use in production.

Overview

Stable array sort() function

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
javascript.builtins.Array.sort.stable_sorting
70
79
3
10.1
70
10.3
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
const items = [
  { name: 'A', priority: 1 },
  { name: 'B', priority: 2 },
  { name: 'C', priority: 1 },
];

items.sort((a, b) => a.priority - b.priority);
// The relative order of A and C is preserved (stable sort)

Live demo

safeso-t. confirm

samepriority hasaitemu. relative order that, so-tafter also keep and inspect it..

PreviewFullscreen

Multiple. sequentialso-t

Name in so-tafter to kacategory in so-t also, Name. order that kacategorywithinkeep..

PreviewFullscreen

scoreorder. keep

score. yu-za- that, order(source. Arrayorder) line up variantchild inspect it..

PreviewFullscreen

Use cases

  • Using Stable array sort

    Stable array sort() function

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features