Sort Lines

Sort lines of text alphabetically with optional reverse order.

Code

Utilities
const lines = text.split('\n').filter(l => l.trim());
const sorted = lines.sort((a, b) => a.localeCompare(b));
return (reverse ? sorted.reverse() : sorted).join('\n');

Parameters

Multi-line text to sort.

Sort in descending order.

Browser·fetch() may be limited by CORS

More JavaScript Snippets