Prev-content

string.localeCompare()

류뚝딱 2018. 11. 12. 16:28

string.localeCompare()

string.localecompare() 메서드는 기준 문자열과 비교했을 때 비교 대상 문자열이 정렬상 전에 오는지, 
후에 오는지 혹은 같은 순서에 배치되는지를 알려주는 숫자를 리턴해준다.
str.localeCompare(비교str)
//stre : 대상 문자
//비교str : 비교할 문자

예제 코드

console.log('a'.localeCompare('b')); // -1
console.log('b'.localeCompare('a')); // 1
console.log('b'.localeCompare('b')); // 0