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

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -