I am trying to sort an array alphabetically in JavaScript. I reduced the size of the array for testing and readability (the original is not that much larger but still getting same problem). Problem is that output has a few values at the top of the list that are not in order. I tried running the sort in a couple different loops many times over and still doesn't seem to sort correctly. I have looked around and most answers are about basic syntax. I have sorted numbers and other lists like this so I am puzzled.
Thanks in advance.
Here is my code:
var miniArr = ['leatherwood', 'sacramento', 'ackerman', 'alma', 'anderson', 'ben wheeler', 'atlanta', 'bakersfield', 'albuquerque', 'baker', 'aspen', 'anchorage', 'antioch', 'benton', 'cedar rapids', 'el cajon', 'boca raton', 'falcon', 'crestview', 'ceres', 'deep run', 'fresno', 'eugene', 'fayetteville', 'fairfield', 'fort myers', 'butler', 'eunice', 'cary', 'cincinnati', 'buffalo', 'freedom (watsonville)', 'francis creek', 'boulder', 'fort worth', 'edgartown', 'bonita', 'glen spey', 'grants pass', 'cleveland', 'clinton', 'colonia', 'chula vista', 'gulf breeze', 'lakeland', 'la mesa', 'jasper', 'haverhill', 'ingleside (canada)', 'joplin', 'hancock', 'pasadena', 'loveland', 'london (canada)', 'lompoc', 'lemon grove', 'park city']
var sorted = [];
var sorted2 = []
for (var x = 0; x < 100; x++) {
sorted = miniArr.sort((a, b) => a > b);
}
for (var x = 0; x < 100; x++) {
sorted2 = sorted.sort((a, b) => a > b);
}
console.log(sorted);
console.log(sorted2);