I am trying to sort a list of objects by a string which is the filename for a song, sometimes the filename includes numbers and letters, but every sorting method I've tried does not sort the filenames in an order you you would expect, such as in my example below, the expected output is:
Track 1
Track 2
Track 10
but it gets sorted incorrectly as:
Track 1
Track 10
Track 2
var inputFiles=[
{
'name':'Track 1.wav'
},
{
'name':'Track 2.wav'
},
{
'name':'Track 10.wav'
},
]
console.log('sort audio files by title: ', inputFiles)
let sortedAudio = inputFiles.sort(function(a, b) {
var textA = a['name'].toUpperCase();
var textB = b['name'].toUpperCase();
return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
});
console.log('sortedAudio=',sortedAudio)