I have an array
var arr = ['hello','"end" two', 'end one', 'yes', 'abc' ];
I need to sort it as shown below
// abc, end one, "end" two, hello, yes
What should i do?
You could sort with a String#localeCompare
's option.
ignorePunctuation
Whether punctuation should be ignored. Possible values are
true
andfalse
; the default isfalse
.
var array = ['hello', '"end" two', 'end one', 'yes', 'abc'];
array.sort(function (a, b) {
return a.localeCompare(b, undefined, { ignorePunctuation: true });
});
console.log(array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With