sort의 진실

저는 지금까지 sort하면 자동으로 숫자적으로 오름차순으로 되는 줄 알았는데 그게 아니라
The sort() method sorts the elements of an array in place and returns the array. The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
이거였습니다.
string으로 변환을 해서 알파벳순(가나다순)으로 정렬이 되는 것이였습니다.
항상 숫자 정렬은 이거네요

.sort((a, b)=>; a - b)
3개의 좋아요