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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -