javascript - Alpha sort according to a specific part of string -
i have list of filenames, each file looking this:
https://www.dropbox.com/s/xxx/nf%208700%test%test%file.pdf?raw=1
these files dynamically put list, don't remain in correct order. i'd sort whole list @ once, end of url (the file name).
like this:
/nf%208700%test%test%file.pdf?raw=1
i can end of file doing this
let index = curr.lastindexof("/"); console.log(curr.slice(index));
but question is, how can sort whole list specific part of string?
possible solution
const data = ['https://www.dropbox.com/s/xxx/nf%2', 'https://www.dropbox.com/s/xxx/nf%1']; const result = data.sort((namea, nameb) => namea.split('/').slice(-1)[0].localecompare(nameb.split('/').slice(-1)[0])); console.log(result);
Comments
Post a Comment