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
Post a Comment