Programming/TypeScript

[ TypeScript ] sort 함수 - 특정 문자열 컬럼기준으로 정렬하기

seulye 2023. 4. 10. 17:26

temp = 데이터셋

name이라는 특정 문자열 컬럼 기준으로 정렬하려면 이렇게 하면 된다. 

 

if (temp.length > 0) {
            temp.sort((a: { name: string }, b: { name: string }) => {
                return a.name.localeCompare(b.name);
            });
        }