// Better to avoid mutations (that will bite you in libraries like React): [...stringArr].sort(); [...stringArr].reverse(); // I generally recommend to use `a` and `z` to make it clear: [...array].sort((a, z) => a - z); [...array].sort((a, z) => z - a); // But you could also make it more readable: [...array].sort((first, second) => first - second); [...array].sort((first, second) => second - first);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter