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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -