javascript - Sort array, but ignore some specific characters in the beginning -


i have array elements being strings. , want sort them alphabetically, know should use sort() function. want happen ignore first few characters based on are.

for example, if there array ['<file> dogs', '<dir> more', '<file> cats'], how make ignore text <file> , , , sort these strings text comes after them? have create custom sorting function?

you strip tags, answer, , take rest string sortable result.

var array =  ['<file> dogs', '<dir> more', '<file> cats'];    array.sort(function (a, b) {      function getraw(s) {          return s.replace(/<(?:.|\n)*?>/gm, '').trim();      }        return getraw(a).localecompare(getraw(b));  });  console.log(array);


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -