Pengurut Array

Urutkan array dan list

Sort Configuration
Input Array
Sorted Array
How Array Sorting Works in JavaScript

JavaScript arrays can be sorted using Array.prototype.sort() with a custom compare function. This tool provides advanced sorting options for different data types.

Example Usage

// Sort numbers
[3, 10, 2].sort((a, b) => a - b)
// Output: [2, 3, 10]

// Sort objects by property
const users = [
  { name: "Alice", age: 30 },
  { name: "Bob", age: 25 }
]
users.sort((a, b) => a.age - b.age)
// Output: [{ name: "Bob", age: 25 }, { name: "Alice", age: 30 }]

// Locale-aware string sorting
['é', 'a', 'z'].sort((a, b) => 
  new Intl.Collator().compare(a, b)
)

Key Features

  • Auto-detect: Automatically identifies array type (string, number, boolean, object, array)
  • Object sorting: Sort by any property, including nested keys (e.g., user.address.city)
  • Array sorting: Sort arrays within arrays by specific index
  • Locale-aware: Uses Intl.Collator for proper international string sorting
  • Null handling: Control where null/undefined values appear in sorted results
  • Remove duplicates: Optionally filter out duplicate entries
  • Custom comparators: Write your own sorting logic for complex scenarios

Common Use Cases

📊 Data Analysis

Sort datasets, CSV data, API responses

🎯 User Interfaces

Table sorting, dropdown options, search results

📝 Data Processing

ETL pipelines, data transformation, batch processing

🔍 Testing & Debugging

Compare arrays, validate sort algorithms, test data